avant de changer la struct config
This commit is contained in:
parent
73855be6f4
commit
1895ade98e
199
config/config.go
199
config/config.go
@ -7,17 +7,29 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
DebugMode bool
|
||||
LogLevel 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"
|
||||
@ -25,11 +37,13 @@ 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
|
||||
@ -39,8 +53,25 @@ var createDescription string
|
||||
var createPrivatge string
|
||||
|
||||
// variables for env command
|
||||
var envVariablesFlag bool = false
|
||||
// -------------------------
|
||||
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
|
||||
}
|
||||
@ -49,6 +80,10 @@ func GetBuildDate() string {
|
||||
return modifDate
|
||||
}
|
||||
|
||||
func GetConfigFileName() string {
|
||||
return ConfigFileYmlName
|
||||
}
|
||||
|
||||
func GetToken() string {
|
||||
return tokenEnv
|
||||
}
|
||||
@ -85,6 +120,22 @@ func SetVerboseFlag(flag bool) {
|
||||
verboseFlag = flag
|
||||
}
|
||||
|
||||
func SetVersionFlag(flag bool) {
|
||||
versionFlag = flag
|
||||
}
|
||||
|
||||
func GetVersionFlag() bool {
|
||||
return versionFlag
|
||||
}
|
||||
|
||||
func SetHelpFlag(flag bool) {
|
||||
helpFlag = flag
|
||||
}
|
||||
|
||||
func GetHelpFlag() bool {
|
||||
return helpFlag
|
||||
}
|
||||
|
||||
// functions for list command
|
||||
// --------------------------
|
||||
func SetListOrganisation(name string) {
|
||||
@ -137,10 +188,79 @@ func SetCreatePrivate(private string) {
|
||||
createPrivatge = private
|
||||
}
|
||||
|
||||
// function for env command
|
||||
// ------------------------
|
||||
func GetEnvVariablesFlag() bool {
|
||||
return EnvVariablesFlag
|
||||
}
|
||||
|
||||
func SetEnvVariablesFlag(flag bool) {
|
||||
EnvVariablesFlag = flag
|
||||
}
|
||||
|
||||
func GetEnvVariablesFilterFlag() bool {
|
||||
return envVariablesFilterFlag
|
||||
}
|
||||
|
||||
func SetEnvVariablesFilterFlag(flag bool) {
|
||||
envVariablesFilterFlag = flag
|
||||
}
|
||||
|
||||
func GetEnvVariablesFilter() string {
|
||||
return envVariablesFilter
|
||||
}
|
||||
|
||||
func SetEnvVariablesFilter(filter string) {
|
||||
envVariablesFilter = filter
|
||||
}
|
||||
|
||||
func GetEnvVariablesListFlag() bool {
|
||||
return ennVariablesListFlag
|
||||
}
|
||||
|
||||
func SetEnvVariablesListFlag(flag bool) {
|
||||
ennVariablesListFlag = flag
|
||||
}
|
||||
|
||||
func GetEnvVariablesYmlFlag() bool {
|
||||
return envVariablesYmlFlag
|
||||
}
|
||||
|
||||
func SetEnvVariablesYmlFlag(flag bool) {
|
||||
envVariablesYmlFlag = flag
|
||||
}
|
||||
|
||||
func GetEnvVariablesCategoryFlag() bool {
|
||||
return envVariablesCategoryFlag
|
||||
}
|
||||
|
||||
func SetEnvVariablesCategoryFlag(flag bool) {
|
||||
envVariablesCategoryFlag = flag
|
||||
}
|
||||
|
||||
func GetEnvVariablesCategory() string {
|
||||
return envVariablesCategory
|
||||
}
|
||||
|
||||
func SetEnvVariablesCategory(category string) {
|
||||
envVariablesCategory = category
|
||||
}
|
||||
|
||||
func GetEnvVariablesSetFlag() bool {
|
||||
return envVariablesSetFlag
|
||||
}
|
||||
|
||||
func SetEnvVariablesSetFlag(flag bool) {
|
||||
envVariablesSetFlag = flag
|
||||
}
|
||||
|
||||
// SetInformations - set informations from command line
|
||||
func SetInformations(cmd *cobra.Command, args []string) {
|
||||
|
||||
// fmt.Println("SetInformations - start:")
|
||||
// Check if the version flag is set
|
||||
if cmd.Flags().Changed("version") || cmd.Flags().Changed("V") {
|
||||
SetVersionFlag(true)
|
||||
}
|
||||
|
||||
// Check if the verbose flag is set
|
||||
if cmd.Flags().Changed("verbose") || cmd.Flags().Changed("v") {
|
||||
@ -156,21 +276,9 @@ func SetInformations(cmd *cobra.Command, args []string) {
|
||||
SetJsonFlag(false)
|
||||
}
|
||||
|
||||
// check if the cmd come from list or create
|
||||
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())
|
||||
}
|
||||
// check if the help flag is set
|
||||
if cmd.Flags().Changed("help") || cmd.Flags().Changed("h") {
|
||||
SetHelpFlag(true)
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("name") || cmd.Flags().Changed("n") {
|
||||
@ -195,6 +303,63 @@ func SetInformations(cmd *cobra.Command, args []string) {
|
||||
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())
|
||||
}
|
||||
|
||||
} 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()) {
|
||||
|
Loading…
Reference in New Issue
Block a user