go-KodeStarter/config/config.go

905 lines
23 KiB
Go
Raw Permalink 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-30 15:25:39 -04:00
"kode-creator/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
2023-06-30 15:25:39 -04:00
GithubTokenEnv string
GitTeaTokenEnv string
2023-06-30 10:09:01 -04:00
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
2023-07-08 00:45:18 -04:00
UserFlag bool
2023-06-30 10:09:01 -04:00
listOrganizationFlag bool
2023-07-08 00:45:18 -04:00
GitHubSearchFlag bool
GitHubSearch string
2023-06-30 10:09:01 -04:00
}
2023-06-12 22:40:22 -04:00
2023-06-30 10:09:01 -04:00
type CreateCmdConfig struct {
2023-07-01 00:49:45 -04:00
Name string
Description string
DirectoryFlag bool
VersionFlag bool
ReadmeFlag bool
GitFlag bool
TeaFlag bool
Organization string
OrganizationFlag bool
PrivateFlag bool
2023-06-30 10:09:01 -04:00
}
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-11-29 12:57:49 -05:00
EnvVariablesKey string
EnvVariablesValue string
EnvVariablesDeleteFlag bool
2023-06-30 10:09:01 -04:00
}
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
}
2023-06-30 15:25:39 -04:00
// Getter for GithubTokenEnv field
func (c *Config) GetGithubTokenEnv() string {
return c.GithubTokenEnv
2023-06-30 10:09:01 -04:00
}
2023-06-30 15:25:39 -04:00
// Setter for GithubTokenEnv field
func (c *Config) SetGithubTokenEnv(value string) {
c.GithubTokenEnv = value
}
// Getter for GithubTokenEnv field
func (c *Config) GetGitTeaTokenEnv() string {
return c.GitTeaTokenEnv
}
// Setter for GithubTokenEnv field
func (c *Config) SetGitTeaTokenEnv(value string) {
c.GitTeaTokenEnv = value
2023-06-30 10:09:01 -04:00
}
// 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-07-08 00:45:18 -04:00
// getter for ListUserFlag
func (c *Config) GetListUserFlag() bool {
return c.ListCmd.UserFlag
}
// setter for ListUserFlag
func (c *Config) SetListUserFlag(value bool) {
c.ListCmd.UserFlag = value
}
// getter for GitHubSearchFlag
func (c *Config) GetGitHubSearchFlag() bool {
return c.ListCmd.GitHubSearchFlag
}
// setter for GitHubSearchFlag
func (c *Config) SetGitHubSearchFlag(value bool) {
c.ListCmd.GitHubSearchFlag = value
}
// getter for GitHubSearch
func (c *Config) GetGitHubSearch() string {
return c.ListCmd.GitHubSearch
}
// setter for GitHubSearch
func (c *Config) SetGitHubSearch(value string) {
c.ListCmd.GitHubSearch = value
}
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-07-01 00:49:45 -04:00
// Getter for Directory field
func (c *Config) GetCreateDirectoryFlag() bool {
return c.CreateCmd.DirectoryFlag
}
// Setter for Directory field
func (c *Config) SetCreateDirectoryFlag(value bool) {
c.CreateCmd.DirectoryFlag = value
}
// Getter for versionFlag field
func (c *Config) GetCreateVersionFlag() bool {
return c.CreateCmd.VersionFlag
}
// Setter for versionFlag field
func (c *Config) SetCreateVersionFlag(value bool) {
c.CreateCmd.VersionFlag = value
}
// Getter for createReadme field
func (c *Config) GetCreateReadmeFlag() bool {
return c.CreateCmd.ReadmeFlag
}
// Setter for createReadme field
func (c *Config) SetCreateReadmeFlag(value bool) {
c.CreateCmd.ReadmeFlag = value
}
// Getter for createGit flag
func (c *Config) GetCreateGitFlag() bool {
return c.CreateCmd.GitFlag
}
// Setter for createGit flag
func (c *Config) SetCreateGitFlag(value bool) {
c.CreateCmd.GitFlag = value
}
// Getter for createTea flag
func (c *Config) GetCreateTeaFlag() bool {
return c.CreateCmd.TeaFlag
}
// Setter for createTea flag
func (c *Config) SetCreateTeaFlag(value bool) {
c.CreateCmd.TeaFlag = value
}
// Getter for create Orgenization field
func (c *Config) GetCreateOrgenization() string {
return c.CreateCmd.Organization
}
// Setter for create Orgenization field
func (c *Config) SetCreateOrgenization(value string) {
c.CreateCmd.Organization = value
}
// Getter for create Orgenization flag
func (c *Config) GetCreateOrgenizationFlag() bool {
return c.CreateCmd.OrganizationFlag
}
// Setter for create Orgenization flag
func (c *Config) SetCreateOrgenizationFlag(value bool) {
c.CreateCmd.OrganizationFlag = value
}
2023-06-30 10:09:01 -04:00
// Getter for createPrivate field
2023-07-01 00:49:45 -04:00
func (c *Config) GetCreatePrivateFlag() bool {
return c.CreateCmd.PrivateFlag
2023-06-17 14:17:02 -04:00
}
2023-06-30 10:09:01 -04:00
// Setter for createPrivate field
2023-07-01 00:49:45 -04:00
func (c *Config) SetCreatePrivateFlag(value bool) {
c.CreateCmd.PrivateFlag = 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-11-29 12:57:49 -05:00
// Getter for env Key
func (c *Config) GetEnvKey() string {
return c.EnvCmd.EnvVariablesKey
}
// Setter for env Key
func (c *Config) SetEnvKey(value string) {
c.EnvCmd.EnvVariablesKey = value
}
// Getter for env Value
func (c *Config) GetEnvValue() string {
return c.EnvCmd.EnvVariablesValue
}
// Setter for env Value
func (c *Config) SetEnvValue(value string) {
c.EnvCmd.EnvVariablesValue = value
}
// Getter for env Delete flag
func (c *Config) GetEnvDeleteFlag() bool {
return c.EnvCmd.EnvVariablesDeleteFlag
}
// Setter for env Delete flag
func (c *Config) SetEnvDeleteFlag(value bool) {
c.EnvCmd.EnvVariablesDeleteFlag = value
}
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
2023-06-30 14:17:21 -04:00
var configFileYmlName string = utils.GetProgramDir() + "/config.yml"
2023-06-30 10:09:01 -04:00
c.SetConfigFileYmlName(configFileYmlName)
2023-06-30 15:25:39 -04:00
// set Github token from environment variable
2023-11-29 12:57:49 -05:00
var githubTokenEnv string = utils.GetGitTokenFromOsEnv()
2023-06-30 15:25:39 -04:00
c.SetGithubTokenEnv(githubTokenEnv)
// set Gitea token from environment variable
2023-11-29 12:57:49 -05:00
var giteaTokenEnv string = utils.GetGitTeaTokenFromOsEnv()
2023-07-08 00:45:18 -04:00
c.SetGitTeaTokenEnv(giteaTokenEnv)
2023-06-30 10:09:01 -04:00
// set verbose flag
c.SetVerboseFlag(false)
// set json flag
c.SetJsonFlag(false)
// set version flag
c.SetVersionFlag(false)
// set help flag
c.SetHelpFlag(false)
2023-11-29 12:57:49 -05:00
// set delete flag
c.SetEnvDeleteFlag(false)
2023-06-30 10:09:01 -04:00
// 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-07-08 00:45:18 -04:00
c.SetListUserFlag(true)
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-07-08 00:45:18 -04:00
if cmd.Flags().Changed("search") || cmd.Flags().Changed("s") {
c.SetGitHubSearchFlag(true)
c.SetGitHubSearch(cmd.Flag("search").Value.String())
}
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 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
2023-07-01 00:49:45 -04:00
if cmd.Flags().Changed("description") || cmd.Flags().Changed("d") {
c.SetCreateDescription(cmd.Flag("description").Value.String())
}
// set Directory flag if set for create directories structure
if cmd.Flags().Changed("struc") || cmd.Flags().Changed("s") {
c.SetCreateDirectoryFlag(true)
// set version flag if set for adding verion control
if cmd.Flags().Changed("version") || cmd.Flags().Changed("v") {
c.SetCreateVersionFlag(true)
}
// set Readme flag if set for adding readme file
if cmd.Flags().Changed("readme") || cmd.Flags().Changed("r") {
c.SetCreateReadmeFlag(true)
}
2023-06-25 12:53:47 -04:00
}
2023-07-01 00:49:45 -04:00
// if Git flag or Tea flag is set
if cmd.Flags().Changed("git") || cmd.Flags().Changed("g") || cmd.Flags().Changed("tea") || cmd.Flags().Changed("t") {
// set private flag if set
if cmd.Flags().Changed("private") || cmd.Flags().Changed("p") {
c.SetCreatePrivateFlag(true)
}
// set organization flag if set
if cmd.Flags().Changed("org") || cmd.Flags().Changed("o") {
c.SetCreateOrgenization(cmd.Flag("org").Value.String())
c.SetCreateOrgenizationFlag(true)
}
// set Git flag if set for creating git repository
if cmd.Flags().Changed("git") || cmd.Flags().Changed("g") {
c.SetCreateGitFlag(true)
} else if cmd.Flags().Changed("tea") || cmd.Flags().Changed("t") {
c.SetCreateTeaFlag(true)
2023-06-30 10:09:01 -04:00
}
}
2023-07-01 00:49:45 -04:00
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:")
2023-11-29 12:57:49 -05:00
fmt.Println("- - - - - - - - - - - - - - - GIT_TOKEN- - - - - - - - - - - - - - -")
2023-06-30 10:09:01 -04:00
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())
2023-06-30 15:25:39 -04:00
fmt.Println("config: GithubTokenEnv: ", c.GetGithubTokenEnv())
fmt.Println("config: GiteaTokenEnv: ", c.GetGitTeaTokenEnv())
2023-06-30 10:09:01 -04:00
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: CreateCmd: ", c.GetCreateCmd())
2023-07-01 00:49:45 -04:00
fmt.Println("config: CreateName: ", c.GetCreateCmd().Name)
fmt.Println("config: CreateDescription: ", c.GetCreateDescription())
fmt.Println("config: CreateDirectory: ", c.GetCreateDirectoryFlag())
fmt.Println("config: VersionFlag", c.GetCreateVersionFlag())
fmt.Println("config: ReadMeFlag ", c.GetCreateReadmeFlag())
fmt.Println("config: GitFlag ", c.GetCreateGitFlag())
fmt.Println("config: TeaFlag ", c.GetCreateTeaFlag())
fmt.Println("config: Organization: ", c.GetCreateOrgenization())
fmt.Println("config: OrganizationFlag: ", c.GetCreateOrgenizationFlag())
fmt.Println("config: CreatePrivate: ", c.GetCreatePrivateFlag())
2023-06-30 10:09:01 -04:00
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())
2023-11-29 12:57:49 -05:00
fmt.Println("config: EnvVariablesShowAllFlag: ", c.GetEnvShowAllFlag())
fmt.Println("config: EnvVariablesKey: ", c.GetEnvKey())
fmt.Println("config: EnvVariablesValue: ", c.GetEnvValue())
fmt.Println("config: EnvVariablesDeleteFlag: ", c.GetEnvDeleteFlag())
2023-06-30 10:09:01 -04:00
fmt.Println("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -")
}