build 0.0.0.25
This commit is contained in:
+572
-247
@@ -3,376 +3,701 @@ package config
|
||||
import (
|
||||
"fmt"
|
||||
"kode-starter/utils"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
DebugMode bool
|
||||
LogLevel string
|
||||
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
|
||||
}
|
||||
|
||||
var author string = "Bruno Charest"
|
||||
|
||||
var modifDate string = "2023-06-12"
|
||||
|
||||
var ConfigFileYmlName string = "config.yml"
|
||||
|
||||
var tokenEnv string = utils.GetGitToken()
|
||||
|
||||
var verboseFlag bool = false
|
||||
|
||||
var jsonFlag bool = false
|
||||
|
||||
var versionFlag bool = false
|
||||
|
||||
var helpFlag bool = false
|
||||
|
||||
// variables for URL
|
||||
// -----------------
|
||||
var urlBase string = "https://git.bcmaison.cf"
|
||||
|
||||
var urlApiBase string = urlBase + "/api/v1"
|
||||
|
||||
var urlApiOrgs string = urlApiBase + "/orgs"
|
||||
|
||||
// variables for list command
|
||||
// --------------------------
|
||||
var listOrganization string
|
||||
|
||||
var listOrganizationFlag bool = false
|
||||
|
||||
// variables for create command
|
||||
// ----------------------------
|
||||
var createName string
|
||||
|
||||
var createOrganisation string
|
||||
|
||||
var createDescription string
|
||||
|
||||
var createPrivatge string
|
||||
|
||||
// variables for env command
|
||||
// -------------------------
|
||||
var EnvVariablesFlag bool = false
|
||||
|
||||
var envVariablesFilterFlag bool = false
|
||||
|
||||
var ennVariablesListFlag bool = false
|
||||
|
||||
var envVariablesFilter string
|
||||
|
||||
var envVariablesYmlFlag bool = false
|
||||
|
||||
var envVariablesCategoryFlag bool = false
|
||||
|
||||
var envVariablesCategory string
|
||||
|
||||
var envVariablesSetFlag bool = false
|
||||
|
||||
// general functions
|
||||
// -----------------
|
||||
func GetAuthor() string {
|
||||
return author
|
||||
type URLConfig struct {
|
||||
Base string
|
||||
ApiBase string
|
||||
ApiOrgs string
|
||||
}
|
||||
|
||||
func GetBuildDate() string {
|
||||
return modifDate
|
||||
type ListCmdConfig struct {
|
||||
Organization string
|
||||
GitFlag bool
|
||||
TeaFlag bool
|
||||
User string
|
||||
listOrganizationFlag bool
|
||||
}
|
||||
|
||||
func GetConfigFileName() string {
|
||||
return ConfigFileYmlName
|
||||
type CreateCmdConfig struct {
|
||||
Name string
|
||||
Organisation string
|
||||
Description string
|
||||
Private bool
|
||||
}
|
||||
|
||||
func GetToken() string {
|
||||
return tokenEnv
|
||||
type EnvCmdConfig struct {
|
||||
EnvVariablesFlag bool
|
||||
EnvVariablesListFlag bool
|
||||
EnvVariablesFilterFlag bool
|
||||
EnvVariablesFilter string
|
||||
EnvVariablesYmlFlag bool
|
||||
EnvVariablesCategoryFlag bool
|
||||
EnvVariablesCategory string
|
||||
EnvVariablesSetFlag bool
|
||||
EnvVariablesShowAllFlag bool
|
||||
}
|
||||
|
||||
func SetToken(token string) {
|
||||
tokenEnv = token
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// **** G E N E R A L GETTER - SETTER ****
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// Getter for DebugMode field
|
||||
func (c *Config) GetDebugMode() bool {
|
||||
return c.DebugMode
|
||||
}
|
||||
|
||||
func GetJsonFlag() bool {
|
||||
return jsonFlag
|
||||
// Setter for DebugMode field
|
||||
func (c *Config) SetDebugMode(value bool) {
|
||||
c.DebugMode = value
|
||||
}
|
||||
|
||||
func SetJsonFlag(flag bool) {
|
||||
jsonFlag = flag
|
||||
// Getter for LogLevel field
|
||||
func (c *Config) GetLogLevel() string {
|
||||
return c.LogLevel
|
||||
}
|
||||
|
||||
func GetUrlBase() string {
|
||||
return urlBase
|
||||
// Setter for LogLevel field
|
||||
func (c *Config) SetLogLevel(value string) {
|
||||
c.LogLevel = value
|
||||
}
|
||||
|
||||
func GetUrlApiBase() string {
|
||||
return urlApiBase
|
||||
// Getter for author field
|
||||
func (c *Config) GetAuthor() string {
|
||||
return c.author
|
||||
}
|
||||
|
||||
func GetUrlApiOrgs() string {
|
||||
return urlApiOrgs
|
||||
// Setter for author field
|
||||
func (c *Config) SetAuthor(value string) {
|
||||
c.author = value
|
||||
}
|
||||
|
||||
func GetVerboseFlag() bool {
|
||||
return verboseFlag
|
||||
// Getter for modifDate field
|
||||
func (c *Config) GetModifDate() string {
|
||||
return c.ModifDate
|
||||
}
|
||||
|
||||
func SetVerboseFlag(flag bool) {
|
||||
verboseFlag = flag
|
||||
// Setter for modifDate field
|
||||
func (c *Config) SetModifDate(value string) {
|
||||
c.ModifDate = value
|
||||
}
|
||||
|
||||
func SetVersionFlag(flag bool) {
|
||||
versionFlag = flag
|
||||
// Getter for ConfigFileYmlName field
|
||||
func (c *Config) GetConfigFileYmlName() string {
|
||||
return c.ConfigFileYmlName
|
||||
}
|
||||
|
||||
func GetVersionFlag() bool {
|
||||
return versionFlag
|
||||
// Setter for ConfigFileYmlName field
|
||||
func (c *Config) SetConfigFileYmlName(value string) {
|
||||
c.ConfigFileYmlName = value
|
||||
}
|
||||
|
||||
func SetHelpFlag(flag bool) {
|
||||
helpFlag = flag
|
||||
// Getter for tokenEnv field
|
||||
func (c *Config) GetTokenEnv() string {
|
||||
return c.TokenEnv
|
||||
}
|
||||
|
||||
func GetHelpFlag() bool {
|
||||
return helpFlag
|
||||
// Setter for tokenEnv field
|
||||
func (c *Config) SetTokenEnv(value string) {
|
||||
c.TokenEnv = value
|
||||
}
|
||||
|
||||
// functions for list command
|
||||
// --------------------------
|
||||
func SetListOrganisation(name string) {
|
||||
listOrganization = name
|
||||
// Getter for verboseFlag field
|
||||
func (c *Config) GetVerboseFlag() bool {
|
||||
return c.VerboseFlag
|
||||
}
|
||||
|
||||
func GetListOrganisation() string {
|
||||
return listOrganization
|
||||
// Setter for verboseFlag field
|
||||
func (c *Config) SetVerboseFlag(value bool) {
|
||||
c.VerboseFlag = value
|
||||
}
|
||||
|
||||
func SetListOrganisationFlag(flag bool) {
|
||||
listOrganizationFlag = flag
|
||||
// Getter for jsonFlag field
|
||||
func (c *Config) GetJsonFlag() bool {
|
||||
return c.JsonFlag
|
||||
}
|
||||
|
||||
func GetListOrganisationFlag() bool {
|
||||
return listOrganizationFlag
|
||||
// Setter for jsonFlag field
|
||||
func (c *Config) SetJsonFlag(value bool) {
|
||||
c.JsonFlag = value
|
||||
}
|
||||
|
||||
// functions for create command
|
||||
// ----------------------------
|
||||
func GetCreateName() string {
|
||||
return createName
|
||||
// Getter for versionFlag field
|
||||
func (c *Config) GetVersionFlag() bool {
|
||||
return c.VersionFlag
|
||||
}
|
||||
|
||||
func SetCreateName(name string) {
|
||||
createName = name
|
||||
// Setter for versionFlag field
|
||||
func (c *Config) SetVersionFlag(value bool) {
|
||||
c.VersionFlag = value
|
||||
}
|
||||
|
||||
func GetCreateOrganisation() string {
|
||||
return createOrganisation
|
||||
// Getter for helpFlag field
|
||||
func (c *Config) GetHelpFlag() bool {
|
||||
return c.HelpFlag
|
||||
}
|
||||
|
||||
func SetCeateOrganisation(organisation string) {
|
||||
createOrganisation = organisation
|
||||
// Setter for helpFlag field
|
||||
func (c *Config) SetHelpFlag(value bool) {
|
||||
c.HelpFlag = value
|
||||
}
|
||||
|
||||
func GetCreateDescription() string {
|
||||
return createDescription
|
||||
// Getter for url field
|
||||
func (c *Config) GetUrl() URLConfig {
|
||||
return c.Url
|
||||
}
|
||||
|
||||
func SetCeateDescription(description string) {
|
||||
createDescription = description
|
||||
// Setter for url field
|
||||
func (c *Config) SetUrl(value URLConfig) {
|
||||
c.Url = value
|
||||
}
|
||||
|
||||
func GetCreatePrivate() string {
|
||||
return createPrivatge
|
||||
// Getter urlBase field
|
||||
func (c *Config) GetUrlBase() string {
|
||||
return c.Url.Base
|
||||
}
|
||||
|
||||
func SetCreatePrivate(private string) {
|
||||
createPrivatge = private
|
||||
// Setter urlBase field
|
||||
func (c *Config) SetUrlBase(value string) {
|
||||
c.Url.Base = value
|
||||
}
|
||||
|
||||
// function for env command
|
||||
// ------------------------
|
||||
func GetEnvVariablesFlag() bool {
|
||||
return EnvVariablesFlag
|
||||
// Getter urlApiBase field
|
||||
func (c *Config) GetUrlApiBase() string {
|
||||
return c.Url.ApiBase
|
||||
}
|
||||
|
||||
func SetEnvVariablesFlag(flag bool) {
|
||||
EnvVariablesFlag = flag
|
||||
// Setter urlApiBase field
|
||||
func (c *Config) SetUrlApiBase(value string) {
|
||||
c.Url.ApiBase = value
|
||||
}
|
||||
|
||||
func GetEnvVariablesFilterFlag() bool {
|
||||
return envVariablesFilterFlag
|
||||
// Getter urlApiOrgs field
|
||||
func (c *Config) GetUrlApiOrgs() string {
|
||||
return c.Url.ApiOrgs
|
||||
}
|
||||
|
||||
func SetEnvVariablesFilterFlag(flag bool) {
|
||||
envVariablesFilterFlag = flag
|
||||
// Setter urlApiOrgs field
|
||||
func (c *Config) SetUrlApiOrgs(value string) {
|
||||
c.Url.ApiOrgs = value
|
||||
}
|
||||
|
||||
func GetEnvVariablesFilter() string {
|
||||
return envVariablesFilter
|
||||
// Getter for applicationName field
|
||||
func (c *Config) GetApplicationName() string {
|
||||
return c.applicationName
|
||||
}
|
||||
|
||||
func SetEnvVariablesFilter(filter string) {
|
||||
envVariablesFilter = filter
|
||||
// Setter for applicationName field
|
||||
func (c *Config) SetApplicationName(value string) {
|
||||
c.applicationName = value
|
||||
}
|
||||
|
||||
func GetEnvVariablesListFlag() bool {
|
||||
return ennVariablesListFlag
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// * * * * L I S T C M D GETTER - SETTER * * * *
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// Getter for listCmd field
|
||||
func (c *Config) GetListCmd() ListCmdConfig {
|
||||
return c.ListCmd
|
||||
}
|
||||
|
||||
func SetEnvVariablesListFlag(flag bool) {
|
||||
ennVariablesListFlag = flag
|
||||
// Setter for listCmd field
|
||||
func (c *Config) SetListCmd(value ListCmdConfig) {
|
||||
c.ListCmd = value
|
||||
}
|
||||
|
||||
func GetEnvVariablesYmlFlag() bool {
|
||||
return envVariablesYmlFlag
|
||||
// Getter for listOrganizationFlag field
|
||||
func (c *Config) GetListOrganizationFlag() bool {
|
||||
return c.ListCmd.listOrganizationFlag
|
||||
}
|
||||
|
||||
func SetEnvVariablesYmlFlag(flag bool) {
|
||||
envVariablesYmlFlag = flag
|
||||
// Setter for listOrganizationFlag field
|
||||
func (c *Config) SetListOrganizationFlag(value bool) {
|
||||
c.ListCmd.listOrganizationFlag = value
|
||||
}
|
||||
|
||||
func GetEnvVariablesCategoryFlag() bool {
|
||||
return envVariablesCategoryFlag
|
||||
// Getter for listOrganization field
|
||||
func (c *Config) GetListOrganization() string {
|
||||
return c.ListCmd.Organization
|
||||
}
|
||||
|
||||
func SetEnvVariablesCategoryFlag(flag bool) {
|
||||
envVariablesCategoryFlag = flag
|
||||
// Setter for listOrganization field
|
||||
func (c *Config) SetListOrganization(value string) {
|
||||
c.ListCmd.Organization = value
|
||||
}
|
||||
|
||||
func GetEnvVariablesCategory() string {
|
||||
return envVariablesCategory
|
||||
// getter for Git flag
|
||||
func (c *Config) GetGitFlag() bool {
|
||||
return c.ListCmd.GitFlag
|
||||
}
|
||||
|
||||
func SetEnvVariablesCategory(category string) {
|
||||
envVariablesCategory = category
|
||||
// setter for Git flag
|
||||
func (c *Config) SetGitFlag(value bool) {
|
||||
c.ListCmd.GitFlag = value
|
||||
}
|
||||
|
||||
func GetEnvVariablesSetFlag() bool {
|
||||
return envVariablesSetFlag
|
||||
// getter for Tea flag
|
||||
func (c *Config) GetTeaFlag() bool {
|
||||
return c.ListCmd.TeaFlag
|
||||
}
|
||||
|
||||
func SetEnvVariablesSetFlag(flag bool) {
|
||||
envVariablesSetFlag = flag
|
||||
// setter for Tea flag
|
||||
func (c *Config) SetTeaFlag(value bool) {
|
||||
c.ListCmd.TeaFlag = value
|
||||
}
|
||||
|
||||
// SetInformations - set informations from command line
|
||||
func SetInformations(cmd *cobra.Command, args []string) {
|
||||
// getter for User
|
||||
func (c *Config) GetListUser() string {
|
||||
return c.ListCmd.User
|
||||
}
|
||||
|
||||
// setter for User
|
||||
func (c *Config) SetListUser(value string) {
|
||||
c.ListCmd.User = value
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// * * * * C R E A T E C M D GETTER - SETTER * * * *
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// Getter for createCmd field
|
||||
func (c *Config) GetCreateCmd() CreateCmdConfig {
|
||||
return c.CreateCmd
|
||||
}
|
||||
|
||||
// Setter for createCmd field
|
||||
func (c *Config) SetCreateCmd(value CreateCmdConfig) {
|
||||
c.CreateCmd = value
|
||||
}
|
||||
|
||||
// Getter for createName field
|
||||
func (c *Config) GetCreateName() string {
|
||||
return c.CreateCmd.Name
|
||||
}
|
||||
|
||||
// Setter for createName field
|
||||
func (c *Config) SetCreateName(value string) {
|
||||
c.CreateCmd.Name = value
|
||||
}
|
||||
|
||||
// Getter for createDescription field
|
||||
func (c *Config) GetCreateDescription() string {
|
||||
return c.CreateCmd.Description
|
||||
}
|
||||
|
||||
// Setter for createDescription field
|
||||
func (c *Config) SetCreateDescription(value string) {
|
||||
c.CreateCmd.Description = value
|
||||
}
|
||||
|
||||
// Getter for createPrivate field
|
||||
func (c *Config) GetCreatePrivate() bool {
|
||||
return c.CreateCmd.Private
|
||||
}
|
||||
|
||||
// Setter for createPrivate field
|
||||
func (c *Config) SetCreatePrivate(value bool) {
|
||||
c.CreateCmd.Private = value
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// * * * * E N V C M D GETTER - SETTER * * * *
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// Getter for envCmd field
|
||||
func (c *Config) GetEnvCmd() EnvCmdConfig {
|
||||
return c.EnvCmd
|
||||
}
|
||||
|
||||
// Setter for envCmd field
|
||||
func (c *Config) SetEnvCmd(value EnvCmdConfig) {
|
||||
c.EnvCmd = value
|
||||
}
|
||||
|
||||
// Getter for envVariblesFlag flag
|
||||
func (c *Config) GetEnvVariblesFlag() bool {
|
||||
return c.EnvCmd.EnvVariablesFlag
|
||||
}
|
||||
|
||||
// Setter for envVariblesFlag flag
|
||||
func (c *Config) SetEnvVariblesFlag(value bool) {
|
||||
c.EnvCmd.EnvVariablesFlag = value
|
||||
}
|
||||
|
||||
// Getter for env list flag
|
||||
func (c *Config) GetEnvListFlag() bool {
|
||||
return c.EnvCmd.EnvVariablesListFlag
|
||||
}
|
||||
|
||||
// Setter for env list flag
|
||||
func (c *Config) SetEnvListFlag(value bool) {
|
||||
c.EnvCmd.EnvVariablesListFlag = value
|
||||
}
|
||||
|
||||
// Getter for env filter flag
|
||||
func (c *Config) GetEnvFilterFlag() bool {
|
||||
return c.EnvCmd.EnvVariablesFilterFlag
|
||||
}
|
||||
|
||||
// Setter for env filter flag
|
||||
func (c *Config) SetEnvFilterFlag(value bool) {
|
||||
c.EnvCmd.EnvVariablesFilterFlag = value
|
||||
}
|
||||
|
||||
// Getter for env filter
|
||||
func (c *Config) GetEnvFilter() string {
|
||||
return c.EnvCmd.EnvVariablesFilter
|
||||
}
|
||||
|
||||
// Setter for env filter
|
||||
func (c *Config) SetEnvFilterInfo(value string) {
|
||||
c.EnvCmd.EnvVariablesFilter = value
|
||||
}
|
||||
|
||||
// Getter for env yml file flag
|
||||
func (c *Config) GetEnvYmlFileFlag() bool {
|
||||
return c.EnvCmd.EnvVariablesYmlFlag
|
||||
}
|
||||
|
||||
// Setter for env yml file flag
|
||||
func (c *Config) SetEnvYmlFileFlag(value bool) {
|
||||
c.EnvCmd.EnvVariablesYmlFlag = value
|
||||
}
|
||||
|
||||
// Getter for env category flag
|
||||
func (c *Config) GetEnvCategoryFlag() bool {
|
||||
return c.EnvCmd.EnvVariablesCategoryFlag
|
||||
}
|
||||
|
||||
// Setter for env category flag
|
||||
func (c *Config) SetEnvCategoryFlag(value bool) {
|
||||
c.EnvCmd.EnvVariablesCategoryFlag = value
|
||||
}
|
||||
|
||||
// Getter for env category Info
|
||||
func (c *Config) GetEnvCategoryInfo() string {
|
||||
return c.EnvCmd.EnvVariablesCategory
|
||||
}
|
||||
|
||||
// Setter for env category Info
|
||||
func (c *Config) SetEnvCategoryInfo(value string) {
|
||||
c.EnvCmd.EnvVariablesCategory = value
|
||||
}
|
||||
|
||||
// Getter for env Set flag
|
||||
func (c *Config) GetEnvSetFlag() bool {
|
||||
return c.EnvCmd.EnvVariablesSetFlag
|
||||
}
|
||||
|
||||
// Setter for env Set flag
|
||||
func (c *Config) SetEnvSetFlag(value bool) {
|
||||
c.EnvCmd.EnvVariablesSetFlag = value
|
||||
}
|
||||
|
||||
// Getter for env Show All flag
|
||||
func (c *Config) GetEnvShowAllFlag() bool {
|
||||
return c.EnvCmd.EnvVariablesShowAllFlag
|
||||
}
|
||||
|
||||
// Setter for env Show All flag
|
||||
func (c *Config) SetEnvShowAllFlag(value bool) {
|
||||
c.EnvCmd.EnvVariablesShowAllFlag = value
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// 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) {
|
||||
|
||||
// Check if the version flag is set
|
||||
if cmd.Flags().Changed("version") || cmd.Flags().Changed("V") {
|
||||
SetVersionFlag(true)
|
||||
c.SetVersionFlag(true)
|
||||
}
|
||||
|
||||
// Check if the verbose flag is set
|
||||
if cmd.Flags().Changed("verbose") || cmd.Flags().Changed("v") {
|
||||
SetVerboseFlag(true)
|
||||
c.SetVerboseFlag(true)
|
||||
} else {
|
||||
SetVerboseFlag(false)
|
||||
c.SetVerboseFlag(false)
|
||||
}
|
||||
|
||||
// Check if the json flag is set
|
||||
if cmd.Flags().Changed("json") || cmd.Flags().Changed("j") {
|
||||
SetJsonFlag(true)
|
||||
c.SetJsonFlag(true)
|
||||
} else {
|
||||
SetJsonFlag(false)
|
||||
c.SetJsonFlag(false)
|
||||
}
|
||||
|
||||
// check if the help flag is set
|
||||
if cmd.Flags().Changed("help") || cmd.Flags().Changed("h") {
|
||||
SetHelpFlag(true)
|
||||
c.SetHelpFlag(true)
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("name") || cmd.Flags().Changed("n") {
|
||||
SetCreateName(cmd.Flag("name").Value.String())
|
||||
}
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// initialize configuration command and flags
|
||||
// for list command
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
func (c *Config) InitCmdList(cmd *cobra.Command, args []string) {
|
||||
|
||||
if cmd.Flags().Changed("org") || cmd.Flags().Changed("o") {
|
||||
if cmd.Name() == "list" {
|
||||
SetListOrganisation(cmd.Flag("org").Value.String())
|
||||
SetListOrganisationFlag(true)
|
||||
c.SetListOrganization(cmd.Flag("org").Value.String())
|
||||
c.SetListOrganizationFlag(true)
|
||||
} else {
|
||||
SetCeateOrganisation(cmd.Flag("org").Value.String())
|
||||
c.SetListOrganization(cmd.Flag("org").Value.String())
|
||||
}
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("user") || cmd.Flags().Changed("u") {
|
||||
c.SetListUser(cmd.Flag("user").Value.String())
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("git") || cmd.Flags().Changed("g") {
|
||||
c.SetGitFlag(true)
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("tea") || cmd.Flags().Changed("a") {
|
||||
c.SetTeaFlag(true)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// initialize configuration for commands and flags
|
||||
// for create command
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
func (c *Config) InitCmdCreate(cmd *cobra.Command, args []string) {
|
||||
|
||||
// initialize configuration for root command
|
||||
// c.InitCmdRoot(cmd, args)
|
||||
|
||||
// validate flag on create command
|
||||
if cmd.Name() == "create" {
|
||||
|
||||
// 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())
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("desc") || cmd.Flags().Changed("d") {
|
||||
SetCeateDescription(cmd.Flag("desc").Value.String())
|
||||
}
|
||||
// set description flag if set
|
||||
if cmd.Flags().Changed("desc") || cmd.Flags().Changed("d") {
|
||||
c.SetCreateDescription(cmd.Flag("desc").Value.String())
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("private") || cmd.Flags().Changed("p") {
|
||||
SetCreatePrivate(cmd.Flag("private").Value.String())
|
||||
}
|
||||
|
||||
// set env variables flag if set
|
||||
if cmd.Flags().Changed("env") || cmd.Flags().Changed("e") {
|
||||
SetEnvVariablesFlag(true)
|
||||
|
||||
// if flag list is set, set filter flag
|
||||
if cmd.Flags().Changed("list") || cmd.Flags().Changed("l") {
|
||||
SetEnvVariablesListFlag(true)
|
||||
|
||||
// set env variables filter flag if set
|
||||
if cmd.Flags().Changed("filter") || cmd.Flags().Changed("f") {
|
||||
SetEnvVariablesFilter(cmd.Flag("filter").Value.String())
|
||||
// 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)
|
||||
}
|
||||
|
||||
} else if cmd.Flags().Changed("yml") || cmd.Flags().Changed("y") {
|
||||
SetEnvVariablesYmlFlag(true)
|
||||
|
||||
// set env variables category flag if set
|
||||
if cmd.Flags().Changed("category") || cmd.Flags().Changed("c") {
|
||||
SetEnvVariablesCategoryFlag(true)
|
||||
SetEnvVariablesCategory(cmd.Flag("category").Value.String())
|
||||
}
|
||||
|
||||
} else if cmd.Flags().Changed("set") || cmd.Flags().Changed("s") {
|
||||
SetEnvVariablesSetFlag(true)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// If verbose flag is set, print informations
|
||||
if GetVerboseFlag() {
|
||||
if cmd.Name() == "list" {
|
||||
fmt.Println("SetInformations - progress list option:")
|
||||
fmt.Println("SetInformations - org:" + cmd.Flag("org").Value.String())
|
||||
fmt.Println("SetInformations - cmd Usertoken:" + cmd.Flag("token").Value.String())
|
||||
}
|
||||
if cmd.Name() == "create" {
|
||||
fmt.Println("SetInformations - progress create option:")
|
||||
fmt.Println("SetInformations - name:" + cmd.Flag("name").Value.String())
|
||||
fmt.Println("SetInformations - description:" + cmd.Flag("desc").Value.String())
|
||||
fmt.Println("SetInformations - private:" + cmd.Flag("private").Value.String())
|
||||
fmt.Println("SetInformations - cmd Usertoken:" + cmd.Flag("token").Value.String())
|
||||
fmt.Println("SetInformations - org:" + cmd.Flag("org").Value.String())
|
||||
}
|
||||
if cmd.Name() == "env" {
|
||||
fmt.Println("SetInformations - progress env option:")
|
||||
// fmt.Println("SetInformations - cmd Usertoken:" + cmd.Flag("token").Value.String())
|
||||
fmt.Println("SetInformations - env:" + cmd.Flag("env").Value.String())
|
||||
fmt.Println("SetInformations - filter:" + cmd.Flag("filter").Value.String())
|
||||
fmt.Println("SetInformations - list:" + cmd.Flag("list").Value.String())
|
||||
fmt.Println("SetInformations - yml:" + cmd.Flag("yml").Value.String())
|
||||
if GetEnvVariablesListFlag() {
|
||||
fmt.Println("SetInformations - category:" + cmd.Flag("category").Value.String())
|
||||
}
|
||||
fmt.Println("SetInformations - set:" + cmd.Flag("set").Value.String())
|
||||
}
|
||||
}
|
||||
|
||||
// Check if token come from flag or env
|
||||
if cmd.Flags().Changed("token") || cmd.Flags().Changed("t") {
|
||||
if utils.IsValidToken(cmd.Flag("token").Value.String()) {
|
||||
SetToken(cmd.Flag("token").Value.String())
|
||||
} else {
|
||||
utils.ExitWithError(10, "Invalid token, format must be 40 characters UUID.")
|
||||
}
|
||||
|
||||
} else {
|
||||
if utils.IsValidToken(utils.GetGitToken()) {
|
||||
SetToken(utils.GetGitToken())
|
||||
} else {
|
||||
utils.ExitWithError(10, "Invalid token, format must be 40 characters UUID.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// 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)
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("yml") || cmd.Flags().Changed("y") {
|
||||
c.SetEnvYmlFileFlag(true)
|
||||
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("set") || cmd.Flags().Changed("s") {
|
||||
c.SetEnvSetFlag(true)
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// 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("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -")
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user