go-KodeStarter/config/config.go

704 lines
17 KiB
Go
Raw Normal View History

2023-06-12 22:40:22 -04:00
package config
import (
2023-06-14 23:33:24 -04:00
"fmt"
2023-06-12 22:40:22 -04:00
"kode-starter/utils"
2023-06-30 10:09:01 -04:00
"time"
2023-06-12 22:40:22 -04:00
"github.com/spf13/cobra"
)
2023-06-25 12:53:47 -04:00
type Config struct {
2023-06-30 10:09:01 -04:00
DebugMode bool
LogLevel string
author string
ModifDate string
ConfigFileYmlName string
TokenEnv string
VerboseFlag bool
JsonFlag bool
VersionFlag bool
HelpFlag bool
Url URLConfig
ListCmd ListCmdConfig
CreateCmd CreateCmdConfig
EnvCmd EnvCmdConfig
applicationName string
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
type URLConfig struct {
Base string
ApiBase string
ApiOrgs string
}
2023-06-12 22:40:22 -04:00
2023-06-30 10:09:01 -04:00
type ListCmdConfig struct {
Organization string
GitFlag bool
TeaFlag bool
User string
listOrganizationFlag bool
}
2023-06-12 22:40:22 -04:00
2023-06-30 10:09:01 -04:00
type CreateCmdConfig struct {
Name string
Organisation string
Description string
Private bool
}
2023-06-25 12:53:47 -04:00
2023-06-30 10:09:01 -04:00
type EnvCmdConfig struct {
EnvVariablesFlag bool
EnvVariablesListFlag bool
EnvVariablesFilterFlag bool
EnvVariablesFilter string
EnvVariablesYmlFlag bool
EnvVariablesCategoryFlag bool
EnvVariablesCategory string
EnvVariablesSetFlag bool
EnvVariablesShowAllFlag bool
}
2023-06-12 22:40:22 -04:00
2023-06-30 10:09:01 -04:00
// * * * * * * * * * * * * * * * * * * * * * * * * //
// **** G E N E R A L GETTER - SETTER ****
// * * * * * * * * * * * * * * * * * * * * * * * * //
2023-06-12 22:40:22 -04:00
2023-06-30 10:09:01 -04:00
// Getter for DebugMode field
func (c *Config) GetDebugMode() bool {
return c.DebugMode
}
2023-06-12 22:40:22 -04:00
2023-06-30 10:09:01 -04:00
// Setter for DebugMode field
func (c *Config) SetDebugMode(value bool) {
c.DebugMode = value
}
2023-06-25 12:53:47 -04:00
2023-06-30 10:09:01 -04:00
// Getter for LogLevel field
func (c *Config) GetLogLevel() string {
return c.LogLevel
}
2023-06-25 12:53:47 -04:00
2023-06-30 10:09:01 -04:00
// Setter for LogLevel field
func (c *Config) SetLogLevel(value string) {
c.LogLevel = value
}
2023-06-12 22:40:22 -04:00
2023-06-30 10:09:01 -04:00
// Getter for author field
func (c *Config) GetAuthor() string {
return c.author
}
2023-06-12 22:40:22 -04:00
2023-06-30 10:09:01 -04:00
// Setter for author field
func (c *Config) SetAuthor(value string) {
c.author = value
}
2023-06-12 22:40:22 -04:00
2023-06-30 10:09:01 -04:00
// Getter for modifDate field
func (c *Config) GetModifDate() string {
return c.ModifDate
}
2023-06-14 23:33:24 -04:00
2023-06-30 10:09:01 -04:00
// Setter for modifDate field
func (c *Config) SetModifDate(value string) {
c.ModifDate = value
}
2023-06-14 23:33:24 -04:00
2023-06-30 10:09:01 -04:00
// Getter for ConfigFileYmlName field
func (c *Config) GetConfigFileYmlName() string {
return c.ConfigFileYmlName
}
// Setter for ConfigFileYmlName field
func (c *Config) SetConfigFileYmlName(value string) {
c.ConfigFileYmlName = value
}
// Getter for tokenEnv field
func (c *Config) GetTokenEnv() string {
return c.TokenEnv
}
// Setter for tokenEnv field
func (c *Config) SetTokenEnv(value string) {
c.TokenEnv = value
}
// Getter for verboseFlag field
func (c *Config) GetVerboseFlag() bool {
return c.VerboseFlag
}
// Setter for verboseFlag field
func (c *Config) SetVerboseFlag(value bool) {
c.VerboseFlag = value
}
// Getter for jsonFlag field
func (c *Config) GetJsonFlag() bool {
return c.JsonFlag
}
2023-06-17 14:17:02 -04:00
2023-06-30 10:09:01 -04:00
// Setter for jsonFlag field
func (c *Config) SetJsonFlag(value bool) {
c.JsonFlag = value
}
2023-06-17 14:17:02 -04:00
2023-06-30 10:09:01 -04:00
// Getter for versionFlag field
func (c *Config) GetVersionFlag() bool {
return c.VersionFlag
}
2023-06-17 14:17:02 -04:00
2023-06-30 10:09:01 -04:00
// Setter for versionFlag field
func (c *Config) SetVersionFlag(value bool) {
c.VersionFlag = value
}
2023-06-12 22:40:22 -04:00
2023-06-30 10:09:01 -04:00
// Getter for helpFlag field
func (c *Config) GetHelpFlag() bool {
return c.HelpFlag
}
2023-06-25 12:53:47 -04:00
2023-06-30 10:09:01 -04:00
// Setter for helpFlag field
func (c *Config) SetHelpFlag(value bool) {
c.HelpFlag = value
}
2023-06-25 12:53:47 -04:00
2023-06-30 10:09:01 -04:00
// Getter for url field
func (c *Config) GetUrl() URLConfig {
return c.Url
}
2023-06-25 12:53:47 -04:00
2023-06-30 10:09:01 -04:00
// Setter for url field
func (c *Config) SetUrl(value URLConfig) {
c.Url = value
}
2023-06-25 12:53:47 -04:00
2023-06-30 10:09:01 -04:00
// Getter urlBase field
func (c *Config) GetUrlBase() string {
return c.Url.Base
}
2023-06-25 12:53:47 -04:00
2023-06-30 10:09:01 -04:00
// Setter urlBase field
func (c *Config) SetUrlBase(value string) {
c.Url.Base = value
}
2023-06-25 12:53:47 -04:00
2023-06-30 10:09:01 -04:00
// Getter urlApiBase field
func (c *Config) GetUrlApiBase() string {
return c.Url.ApiBase
}
2023-06-21 11:50:12 -04:00
2023-06-30 10:09:01 -04:00
// Setter urlApiBase field
func (c *Config) SetUrlApiBase(value string) {
c.Url.ApiBase = value
}
2023-06-25 12:53:47 -04:00
2023-06-30 10:09:01 -04:00
// Getter urlApiOrgs field
func (c *Config) GetUrlApiOrgs() string {
return c.Url.ApiOrgs
2023-06-12 22:40:22 -04:00
}
2023-06-30 10:09:01 -04:00
// Setter urlApiOrgs field
func (c *Config) SetUrlApiOrgs(value string) {
c.Url.ApiOrgs = value
2023-06-12 22:40:22 -04:00
}
2023-06-30 10:09:01 -04:00
// Getter for applicationName field
func (c *Config) GetApplicationName() string {
return c.applicationName
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
// Setter for applicationName field
func (c *Config) SetApplicationName(value string) {
c.applicationName = value
2023-06-12 22:40:22 -04:00
}
2023-06-30 10:09:01 -04:00
// * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * L I S T C M D GETTER - SETTER * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * //
// Getter for listCmd field
func (c *Config) GetListCmd() ListCmdConfig {
return c.ListCmd
2023-06-12 22:40:22 -04:00
}
2023-06-30 10:09:01 -04:00
// Setter for listCmd field
func (c *Config) SetListCmd(value ListCmdConfig) {
c.ListCmd = value
2023-06-12 22:40:22 -04:00
}
2023-06-30 10:09:01 -04:00
// Getter for listOrganizationFlag field
func (c *Config) GetListOrganizationFlag() bool {
return c.ListCmd.listOrganizationFlag
2023-06-12 22:40:22 -04:00
}
2023-06-30 10:09:01 -04:00
// Setter for listOrganizationFlag field
func (c *Config) SetListOrganizationFlag(value bool) {
c.ListCmd.listOrganizationFlag = value
2023-06-12 22:40:22 -04:00
}
2023-06-30 10:09:01 -04:00
// Getter for listOrganization field
func (c *Config) GetListOrganization() string {
return c.ListCmd.Organization
2023-06-12 22:40:22 -04:00
}
2023-06-30 10:09:01 -04:00
// Setter for listOrganization field
func (c *Config) SetListOrganization(value string) {
c.ListCmd.Organization = value
2023-06-12 22:40:22 -04:00
}
2023-06-30 10:09:01 -04:00
// getter for Git flag
func (c *Config) GetGitFlag() bool {
return c.ListCmd.GitFlag
2023-06-12 22:40:22 -04:00
}
2023-06-30 10:09:01 -04:00
// setter for Git flag
func (c *Config) SetGitFlag(value bool) {
c.ListCmd.GitFlag = value
2023-06-12 22:40:22 -04:00
}
2023-06-30 10:09:01 -04:00
// getter for Tea flag
func (c *Config) GetTeaFlag() bool {
return c.ListCmd.TeaFlag
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
// setter for Tea flag
func (c *Config) SetTeaFlag(value bool) {
c.ListCmd.TeaFlag = value
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
// getter for User
func (c *Config) GetListUser() string {
return c.ListCmd.User
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
// setter for User
func (c *Config) SetListUser(value string) {
c.ListCmd.User = value
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * C R E A T E C M D GETTER - SETTER * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Getter for createCmd field
func (c *Config) GetCreateCmd() CreateCmdConfig {
return c.CreateCmd
2023-06-17 14:17:02 -04:00
}
2023-06-30 10:09:01 -04:00
// Setter for createCmd field
func (c *Config) SetCreateCmd(value CreateCmdConfig) {
c.CreateCmd = value
2023-06-17 14:17:02 -04:00
}
2023-06-30 10:09:01 -04:00
// Getter for createName field
func (c *Config) GetCreateName() string {
return c.CreateCmd.Name
2023-06-17 14:17:02 -04:00
}
2023-06-30 10:09:01 -04:00
// Setter for createName field
func (c *Config) SetCreateName(value string) {
c.CreateCmd.Name = value
2023-06-17 14:17:02 -04:00
}
2023-06-30 10:09:01 -04:00
// Getter for createDescription field
func (c *Config) GetCreateDescription() string {
return c.CreateCmd.Description
2023-06-17 14:17:02 -04:00
}
2023-06-30 10:09:01 -04:00
// Setter for createDescription field
func (c *Config) SetCreateDescription(value string) {
c.CreateCmd.Description = value
2023-06-17 14:17:02 -04:00
}
2023-06-30 10:09:01 -04:00
// Getter for createPrivate field
func (c *Config) GetCreatePrivate() bool {
return c.CreateCmd.Private
2023-06-17 14:17:02 -04:00
}
2023-06-30 10:09:01 -04:00
// Setter for createPrivate field
func (c *Config) SetCreatePrivate(value bool) {
c.CreateCmd.Private = value
2023-06-17 14:17:02 -04:00
}
2023-06-30 10:09:01 -04:00
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * E N V C M D GETTER - SETTER * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Getter for envCmd field
func (c *Config) GetEnvCmd() EnvCmdConfig {
return c.EnvCmd
2023-06-17 14:17:02 -04:00
}
2023-06-30 10:09:01 -04:00
// Setter for envCmd field
func (c *Config) SetEnvCmd(value EnvCmdConfig) {
c.EnvCmd = value
2023-06-17 14:17:02 -04:00
}
2023-06-30 10:09:01 -04:00
// Getter for envVariblesFlag flag
func (c *Config) GetEnvVariblesFlag() bool {
return c.EnvCmd.EnvVariablesFlag
2023-06-17 14:17:02 -04:00
}
2023-06-30 10:09:01 -04:00
// Setter for envVariblesFlag flag
func (c *Config) SetEnvVariblesFlag(value bool) {
c.EnvCmd.EnvVariablesFlag = value
2023-06-17 14:17:02 -04:00
}
2023-06-30 10:09:01 -04:00
// Getter for env list flag
func (c *Config) GetEnvListFlag() bool {
return c.EnvCmd.EnvVariablesListFlag
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
// Setter for env list flag
func (c *Config) SetEnvListFlag(value bool) {
c.EnvCmd.EnvVariablesListFlag = value
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
// Getter for env filter flag
func (c *Config) GetEnvFilterFlag() bool {
return c.EnvCmd.EnvVariablesFilterFlag
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
// Setter for env filter flag
func (c *Config) SetEnvFilterFlag(value bool) {
c.EnvCmd.EnvVariablesFilterFlag = value
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
// Getter for env filter
func (c *Config) GetEnvFilter() string {
return c.EnvCmd.EnvVariablesFilter
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
// Setter for env filter
func (c *Config) SetEnvFilterInfo(value string) {
c.EnvCmd.EnvVariablesFilter = value
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
// Getter for env yml file flag
func (c *Config) GetEnvYmlFileFlag() bool {
return c.EnvCmd.EnvVariablesYmlFlag
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
// Setter for env yml file flag
func (c *Config) SetEnvYmlFileFlag(value bool) {
c.EnvCmd.EnvVariablesYmlFlag = value
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
// Getter for env category flag
func (c *Config) GetEnvCategoryFlag() bool {
return c.EnvCmd.EnvVariablesCategoryFlag
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
// Setter for env category flag
func (c *Config) SetEnvCategoryFlag(value bool) {
c.EnvCmd.EnvVariablesCategoryFlag = value
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
// Getter for env category Info
func (c *Config) GetEnvCategoryInfo() string {
return c.EnvCmd.EnvVariablesCategory
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
// Setter for env category Info
func (c *Config) SetEnvCategoryInfo(value string) {
c.EnvCmd.EnvVariablesCategory = value
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
// Getter for env Set flag
func (c *Config) GetEnvSetFlag() bool {
return c.EnvCmd.EnvVariablesSetFlag
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
// Setter for env Set flag
func (c *Config) SetEnvSetFlag(value bool) {
c.EnvCmd.EnvVariablesSetFlag = value
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
// Getter for env Show All flag
func (c *Config) GetEnvShowAllFlag() bool {
return c.EnvCmd.EnvVariablesShowAllFlag
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
// Setter for env Show All flag
func (c *Config) SetEnvShowAllFlag(value bool) {
c.EnvCmd.EnvVariablesShowAllFlag = value
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// initialize basic configuration
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
func (c *Config) Init() {
// autor
var author string = "Bruno Charest"
// Cfg.SetAuthor(author)
c.SetAuthor(author)
// set modification date to current date
var modifDate string = time.Now().Format("2006-01-02")
c.SetModifDate(modifDate)
// set config file name
var configFileYmlName string = "config.yml"
c.SetConfigFileYmlName(configFileYmlName)
// set token from environment variable
var tokenEnv string = utils.GetGitTokenFromOsEnv()
c.SetTokenEnv(tokenEnv)
// set verbose flag
c.SetVerboseFlag(false)
// set json flag
c.SetJsonFlag(false)
// set version flag
c.SetVersionFlag(false)
// set help flag
c.SetHelpFlag(false)
// set url base
var urlBase string = "https://git.bcmaison.cf"
c.SetUrlBase(urlBase)
// set url api base
var urlApiBase string = urlBase + "/api/v1"
c.SetUrlApiBase(urlApiBase)
// set url api orgs
var urlApiOrgs string = urlApiBase + "/orgs"
c.SetUrlApiOrgs(urlApiOrgs)
//set application name
var appName string = "Kode-Creator"
c.SetApplicationName(appName)
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// initialize configuration for commands and flags
// for root command
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
func (c *Config) InitCmdRoot(cmd *cobra.Command, args []string) {
2023-06-17 14:17:02 -04:00
2023-06-25 12:53:47 -04:00
// Check if the version flag is set
if cmd.Flags().Changed("version") || cmd.Flags().Changed("V") {
2023-06-30 10:09:01 -04:00
c.SetVersionFlag(true)
2023-06-25 12:53:47 -04:00
}
2023-06-17 14:17:02 -04:00
2023-06-12 22:40:22 -04:00
// Check if the verbose flag is set
if cmd.Flags().Changed("verbose") || cmd.Flags().Changed("v") {
2023-06-30 10:09:01 -04:00
c.SetVerboseFlag(true)
2023-06-12 22:40:22 -04:00
} else {
2023-06-30 10:09:01 -04:00
c.SetVerboseFlag(false)
2023-06-12 22:40:22 -04:00
}
// Check if the json flag is set
if cmd.Flags().Changed("json") || cmd.Flags().Changed("j") {
2023-06-30 10:09:01 -04:00
c.SetJsonFlag(true)
2023-06-12 22:40:22 -04:00
} else {
2023-06-30 10:09:01 -04:00
c.SetJsonFlag(false)
2023-06-12 22:40:22 -04:00
}
2023-06-25 12:53:47 -04:00
// check if the help flag is set
if cmd.Flags().Changed("help") || cmd.Flags().Changed("h") {
2023-06-30 10:09:01 -04:00
c.SetHelpFlag(true)
2023-06-17 14:17:02 -04:00
}
2023-06-30 10:09:01 -04:00
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// initialize configuration command and flags
// for list command
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
func (c *Config) InitCmdList(cmd *cobra.Command, args []string) {
2023-06-17 14:17:02 -04:00
if cmd.Flags().Changed("org") || cmd.Flags().Changed("o") {
if cmd.Name() == "list" {
2023-06-30 10:09:01 -04:00
c.SetListOrganization(cmd.Flag("org").Value.String())
c.SetListOrganizationFlag(true)
2023-06-17 14:17:02 -04:00
} else {
2023-06-30 10:09:01 -04:00
c.SetListOrganization(cmd.Flag("org").Value.String())
2023-06-17 14:17:02 -04:00
}
2023-06-30 10:09:01 -04:00
}
2023-06-17 14:17:02 -04:00
2023-06-30 10:09:01 -04:00
if cmd.Flags().Changed("user") || cmd.Flags().Changed("u") {
c.SetListUser(cmd.Flag("user").Value.String())
2023-06-17 14:17:02 -04:00
}
2023-06-30 10:09:01 -04:00
if cmd.Flags().Changed("git") || cmd.Flags().Changed("g") {
c.SetGitFlag(true)
2023-06-17 14:17:02 -04:00
}
2023-06-30 10:09:01 -04:00
if cmd.Flags().Changed("tea") || cmd.Flags().Changed("a") {
c.SetTeaFlag(true)
2023-06-17 14:17:02 -04:00
}
2023-06-30 10:09:01 -04:00
}
2023-06-25 12:53:47 -04:00
2023-06-30 10:09:01 -04:00
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// initialize configuration for commands and flags
// for create command
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
func (c *Config) InitCmdCreate(cmd *cobra.Command, args []string) {
2023-06-25 12:53:47 -04:00
2023-06-30 10:09:01 -04:00
// initialize configuration for root command
// c.InitCmdRoot(cmd, args)
2023-06-25 12:53:47 -04:00
2023-06-30 10:09:01 -04:00
// validate flag on create command
if cmd.Name() == "create" {
2023-06-25 12:53:47 -04:00
2023-06-30 10:09:01 -04:00
// set organization flag if set
if cmd.Flags().Changed("org") || cmd.Flags().Changed("o") {
c.SetListOrganization(cmd.Flag("org").Value.String())
c.SetListOrganizationFlag(true)
}
// set name flag if set
if cmd.Flags().Changed("name") || cmd.Flags().Changed("n") {
c.SetCreateName(cmd.Flag("name").Value.String())
}
2023-06-25 12:53:47 -04:00
2023-06-30 10:09:01 -04:00
// set description flag if set
if cmd.Flags().Changed("desc") || cmd.Flags().Changed("d") {
c.SetCreateDescription(cmd.Flag("desc").Value.String())
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
// set private flag if set
if cmd.Flags().Changed("private") || cmd.Flags().Changed("p") {
if cmd.Flag("private").Value.String() == "true" {
c.SetCreatePrivate(true)
} else if cmd.Flag("private").Value.String() == "false" {
c.SetCreatePrivate(false)
} else {
c.SetCreatePrivate(false)
}
}
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// initialize configuration commands and flags
// for env command
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
func (c *Config) InitCmdEnv(cmd *cobra.Command, args []string) {
// initialize configuration for root command
c.InitCmdRoot(cmd, args)
// validate flag on env command
if cmd.Name() == "env" {
// if flag list is set, set filter flag
if cmd.Flags().Changed("list") || cmd.Flags().Changed("l") {
c.SetEnvListFlag(true)
// // set env variables filter flag if set
// if cmd.Flags().Changed("filter") || cmd.Flags().Changed("f") {
// c.SetEnvFilterInfo(cmd.Flag("filter").Value.String())
// c.SetEnvFilterFlag(true)
// }
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
// set env variables filter flag if set
if cmd.Flags().Changed("filter") || cmd.Flags().Changed("f") {
c.SetEnvFilterInfo(cmd.Flag("filter").Value.String())
c.SetEnvFilterFlag(true)
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
if cmd.Flags().Changed("yml") || cmd.Flags().Changed("y") {
c.SetEnvYmlFileFlag(true)
2023-06-25 12:53:47 -04:00
}
2023-06-30 10:09:01 -04:00
if cmd.Flags().Changed("set") || cmd.Flags().Changed("s") {
c.SetEnvSetFlag(true)
2023-06-12 22:40:22 -04:00
}
2023-06-30 10:09:01 -04:00
// set env variables category flag if set
if cmd.Flags().Changed("cat") || cmd.Flags().Changed("c") {
fmt.Println("cat flag set")
c.SetEnvCategoryFlag(true)
c.SetEnvCategoryInfo(cmd.Flag("cat").Value.String())
}
// set env variables show all flag if set
if cmd.Flags().Changed("all") || cmd.Flags().Changed("a") {
c.SetEnvShowAllFlag(true)
2023-06-12 22:40:22 -04:00
}
2023-06-30 10:09:01 -04:00
}
}
// function that print all configuration if DebugMode is true
func (c *Config) DebugPrintConfig(section string) {
if c.GetDebugMode() {
fmt.Println("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -")
fmt.Println("| Section: " + section)
fmt.Println("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -")
c.printAllConfiguration()
}
}
// function that print string if DebugMode is true
func (c *Config) DebugPrintString(str string) {
if c.GetDebugMode() {
fmt.Println(str)
2023-06-12 22:40:22 -04:00
}
}
2023-06-30 10:09:01 -04:00
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// function to print all configuration
// for information and flags
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
func (c *Config) printAllConfiguration() {
fmt.Println("General Configuration:")
fmt.Println("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -")
fmt.Println("Config: DebugMode: ", c.GetDebugMode())
fmt.Println("Config: LogLevel: ", c.GetLogLevel())
fmt.Println("config: Author: ", c.GetAuthor())
fmt.Println("config: ModifDate: ", c.GetModifDate())
fmt.Println("config: ConfigFileYmlName: ", c.GetConfigFileYmlName())
fmt.Println("config: TokenEnv: ", c.GetTokenEnv())
fmt.Println("config: VerboseFlag: ", c.GetVerboseFlag())
fmt.Println("config: JsonFlag: ", c.GetJsonFlag())
fmt.Println("config: VersionFlag: ", c.GetVersionFlag())
fmt.Println("config: HelpFlag: ", c.GetHelpFlag())
fmt.Println("config: UrlBase: ", c.GetUrlBase())
fmt.Println("config: UrlApiBase: ", c.GetUrlApiBase())
fmt.Println("config: UrlApiOrgs: ", c.GetUrlApiOrgs())
fmt.Println("List Commands Configuration:")
fmt.Println("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -")
fmt.Println("config: ListOrganization: ", c.GetListOrganization())
fmt.Println("config: ListOrganizationFlag: ", c.GetListOrganizationFlag())
fmt.Println("Create commands Configuration:")
fmt.Println("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -")
fmt.Println("config: CreateName: ", c.GetCreateCmd().Name)
fmt.Println("config: Organization: ", c.GetCreateCmd().Organisation)
fmt.Println("config: CreateDescription: ", c.GetCreateCmd().Description)
fmt.Println("config: CreatePrivate: ", c.GetCreatePrivate())
fmt.Println("config: CreateCmd: ", c.GetCreateCmd())
fmt.Println("Environment Variables Configuration:")
fmt.Println("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -")
fmt.Println("config: EnvCmd: ", c.GetEnvCmd())
fmt.Println("config: EnvVariablesFlag: ", c.GetEnvVariblesFlag())
fmt.Println("config: EnvListFlag: ", c.GetEnvListFlag())
fmt.Println("config: EnvFilterFlag: ", c.GetEnvFilterFlag())
fmt.Println("config: EnvVariablesFilter: ", c.GetEnvFilter())
fmt.Println("config: EnvVariablesYmlFlag: ", c.GetEnvYmlFileFlag())
fmt.Println("config: EnvVariablesCategoryFlag: ", c.GetEnvCategoryFlag())
fmt.Println("config: EnvVariablesCategory: ", c.GetEnvCategoryInfo())
fmt.Println("config: EnvVariablesSetFlag: ", c.GetEnvSetFlag())
fmt.Println("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -")
}