905 lines
23 KiB
Go
905 lines
23 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"kode-creator/utils"
|
|
"time"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
type Config struct {
|
|
DebugMode bool
|
|
LogLevel string
|
|
author string
|
|
ModifDate string
|
|
ConfigFileYmlName string
|
|
TokenEnv string
|
|
GithubTokenEnv string
|
|
GitTeaTokenEnv string
|
|
VerboseFlag bool
|
|
JsonFlag bool
|
|
VersionFlag bool
|
|
HelpFlag bool
|
|
Url URLConfig
|
|
ListCmd ListCmdConfig
|
|
CreateCmd CreateCmdConfig
|
|
EnvCmd EnvCmdConfig
|
|
applicationName string
|
|
}
|
|
|
|
type URLConfig struct {
|
|
Base string
|
|
ApiBase string
|
|
ApiOrgs string
|
|
}
|
|
|
|
type ListCmdConfig struct {
|
|
Organization string
|
|
GitFlag bool
|
|
TeaFlag bool
|
|
User string
|
|
UserFlag bool
|
|
listOrganizationFlag bool
|
|
GitHubSearchFlag bool
|
|
GitHubSearch string
|
|
}
|
|
|
|
type CreateCmdConfig struct {
|
|
Name string
|
|
Description string
|
|
DirectoryFlag bool
|
|
VersionFlag bool
|
|
ReadmeFlag bool
|
|
GitFlag bool
|
|
TeaFlag bool
|
|
Organization string
|
|
OrganizationFlag bool
|
|
PrivateFlag bool
|
|
}
|
|
|
|
type EnvCmdConfig struct {
|
|
EnvVariablesFlag bool
|
|
EnvVariablesListFlag bool
|
|
EnvVariablesFilterFlag bool
|
|
EnvVariablesFilter string
|
|
EnvVariablesYmlFlag bool
|
|
EnvVariablesCategoryFlag bool
|
|
EnvVariablesCategory string
|
|
EnvVariablesSetFlag bool
|
|
EnvVariablesShowAllFlag bool
|
|
EnvVariablesKey string
|
|
EnvVariablesValue string
|
|
EnvVariablesDeleteFlag bool
|
|
}
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
// **** G E N E R A L GETTER - SETTER ****
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
// Getter for DebugMode field
|
|
func (c *Config) GetDebugMode() bool {
|
|
return c.DebugMode
|
|
}
|
|
|
|
// Setter for DebugMode field
|
|
func (c *Config) SetDebugMode(value bool) {
|
|
c.DebugMode = value
|
|
}
|
|
|
|
// Getter for LogLevel field
|
|
func (c *Config) GetLogLevel() string {
|
|
return c.LogLevel
|
|
}
|
|
|
|
// Setter for LogLevel field
|
|
func (c *Config) SetLogLevel(value string) {
|
|
c.LogLevel = value
|
|
}
|
|
|
|
// Getter for author field
|
|
func (c *Config) GetAuthor() string {
|
|
return c.author
|
|
}
|
|
|
|
// Setter for author field
|
|
func (c *Config) SetAuthor(value string) {
|
|
c.author = value
|
|
}
|
|
|
|
// Getter for modifDate field
|
|
func (c *Config) GetModifDate() string {
|
|
return c.ModifDate
|
|
}
|
|
|
|
// Setter for modifDate field
|
|
func (c *Config) SetModifDate(value string) {
|
|
c.ModifDate = value
|
|
}
|
|
|
|
// 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 GithubTokenEnv field
|
|
func (c *Config) GetGithubTokenEnv() string {
|
|
return c.GithubTokenEnv
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// Setter for jsonFlag field
|
|
func (c *Config) SetJsonFlag(value bool) {
|
|
c.JsonFlag = value
|
|
}
|
|
|
|
// Getter for versionFlag field
|
|
func (c *Config) GetVersionFlag() bool {
|
|
return c.VersionFlag
|
|
}
|
|
|
|
// Setter for versionFlag field
|
|
func (c *Config) SetVersionFlag(value bool) {
|
|
c.VersionFlag = value
|
|
}
|
|
|
|
// Getter for helpFlag field
|
|
func (c *Config) GetHelpFlag() bool {
|
|
return c.HelpFlag
|
|
}
|
|
|
|
// Setter for helpFlag field
|
|
func (c *Config) SetHelpFlag(value bool) {
|
|
c.HelpFlag = value
|
|
}
|
|
|
|
// Getter for url field
|
|
func (c *Config) GetUrl() URLConfig {
|
|
return c.Url
|
|
}
|
|
|
|
// Setter for url field
|
|
func (c *Config) SetUrl(value URLConfig) {
|
|
c.Url = value
|
|
}
|
|
|
|
// Getter urlBase field
|
|
func (c *Config) GetUrlBase() string {
|
|
return c.Url.Base
|
|
}
|
|
|
|
// Setter urlBase field
|
|
func (c *Config) SetUrlBase(value string) {
|
|
c.Url.Base = value
|
|
}
|
|
|
|
// Getter urlApiBase field
|
|
func (c *Config) GetUrlApiBase() string {
|
|
return c.Url.ApiBase
|
|
}
|
|
|
|
// Setter urlApiBase field
|
|
func (c *Config) SetUrlApiBase(value string) {
|
|
c.Url.ApiBase = value
|
|
}
|
|
|
|
// Getter urlApiOrgs field
|
|
func (c *Config) GetUrlApiOrgs() string {
|
|
return c.Url.ApiOrgs
|
|
}
|
|
|
|
// Setter urlApiOrgs field
|
|
func (c *Config) SetUrlApiOrgs(value string) {
|
|
c.Url.ApiOrgs = value
|
|
}
|
|
|
|
// Getter for applicationName field
|
|
func (c *Config) GetApplicationName() string {
|
|
return c.applicationName
|
|
}
|
|
|
|
// Setter for applicationName field
|
|
func (c *Config) SetApplicationName(value string) {
|
|
c.applicationName = value
|
|
}
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
// * * * * L I S T C M D GETTER - SETTER * * * *
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
// Getter for listCmd field
|
|
func (c *Config) GetListCmd() ListCmdConfig {
|
|
return c.ListCmd
|
|
}
|
|
|
|
// Setter for listCmd field
|
|
func (c *Config) SetListCmd(value ListCmdConfig) {
|
|
c.ListCmd = value
|
|
}
|
|
|
|
// Getter for listOrganizationFlag field
|
|
func (c *Config) GetListOrganizationFlag() bool {
|
|
return c.ListCmd.listOrganizationFlag
|
|
}
|
|
|
|
// Setter for listOrganizationFlag field
|
|
func (c *Config) SetListOrganizationFlag(value bool) {
|
|
c.ListCmd.listOrganizationFlag = value
|
|
}
|
|
|
|
// Getter for listOrganization field
|
|
func (c *Config) GetListOrganization() string {
|
|
return c.ListCmd.Organization
|
|
}
|
|
|
|
// Setter for listOrganization field
|
|
func (c *Config) SetListOrganization(value string) {
|
|
c.ListCmd.Organization = value
|
|
}
|
|
|
|
// getter for Git flag
|
|
func (c *Config) GetGitFlag() bool {
|
|
return c.ListCmd.GitFlag
|
|
}
|
|
|
|
// setter for Git flag
|
|
func (c *Config) SetGitFlag(value bool) {
|
|
c.ListCmd.GitFlag = value
|
|
}
|
|
|
|
// getter for Tea flag
|
|
func (c *Config) GetTeaFlag() bool {
|
|
return c.ListCmd.TeaFlag
|
|
}
|
|
|
|
// setter for Tea flag
|
|
func (c *Config) SetTeaFlag(value bool) {
|
|
c.ListCmd.TeaFlag = value
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
// * * * * 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 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
|
|
}
|
|
|
|
// Getter for createPrivate field
|
|
func (c *Config) GetCreatePrivateFlag() bool {
|
|
return c.CreateCmd.PrivateFlag
|
|
}
|
|
|
|
// Setter for createPrivate field
|
|
func (c *Config) SetCreatePrivateFlag(value bool) {
|
|
c.CreateCmd.PrivateFlag = 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
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
// 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 = utils.GetProgramDir() + "/config.yml"
|
|
c.SetConfigFileYmlName(configFileYmlName)
|
|
|
|
// set Github token from environment variable
|
|
var githubTokenEnv string = utils.GetGitTokenFromOsEnv()
|
|
c.SetGithubTokenEnv(githubTokenEnv)
|
|
|
|
// set Gitea token from environment variable
|
|
var giteaTokenEnv string = utils.GetGitTeaTokenFromOsEnv()
|
|
c.SetGitTeaTokenEnv(giteaTokenEnv)
|
|
|
|
// 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 delete flag
|
|
c.SetEnvDeleteFlag(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") {
|
|
c.SetVersionFlag(true)
|
|
}
|
|
|
|
// Check if the verbose flag is set
|
|
if cmd.Flags().Changed("verbose") || cmd.Flags().Changed("v") {
|
|
c.SetVerboseFlag(true)
|
|
} else {
|
|
c.SetVerboseFlag(false)
|
|
}
|
|
|
|
// Check if the json flag is set
|
|
if cmd.Flags().Changed("json") || cmd.Flags().Changed("j") {
|
|
c.SetJsonFlag(true)
|
|
} else {
|
|
c.SetJsonFlag(false)
|
|
}
|
|
|
|
// check if the help flag is set
|
|
if cmd.Flags().Changed("help") || cmd.Flags().Changed("h") {
|
|
c.SetHelpFlag(true)
|
|
}
|
|
|
|
}
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
// 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" {
|
|
c.SetListOrganization(cmd.Flag("org").Value.String())
|
|
c.SetListOrganizationFlag(true)
|
|
} else {
|
|
c.SetListOrganization(cmd.Flag("org").Value.String())
|
|
}
|
|
}
|
|
|
|
if cmd.Flags().Changed("user") || cmd.Flags().Changed("u") {
|
|
c.SetListUser(cmd.Flag("user").Value.String())
|
|
c.SetListUserFlag(true)
|
|
}
|
|
|
|
if cmd.Flags().Changed("git") || cmd.Flags().Changed("g") {
|
|
c.SetGitFlag(true)
|
|
}
|
|
|
|
if cmd.Flags().Changed("tea") || cmd.Flags().Changed("a") {
|
|
c.SetTeaFlag(true)
|
|
}
|
|
|
|
if cmd.Flags().Changed("search") || cmd.Flags().Changed("s") {
|
|
c.SetGitHubSearchFlag(true)
|
|
c.SetGitHubSearch(cmd.Flag("search").Value.String())
|
|
}
|
|
|
|
}
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
// 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 name flag if set
|
|
if cmd.Flags().Changed("name") || cmd.Flags().Changed("n") {
|
|
c.SetCreateName(cmd.Flag("name").Value.String())
|
|
}
|
|
|
|
// set description flag if set
|
|
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)
|
|
}
|
|
|
|
}
|
|
|
|
// 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)
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
// 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("- - - - - - - - - - - - - - - GIT_TOKEN- - - - - - - - - - - - - - -")
|
|
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: GithubTokenEnv: ", c.GetGithubTokenEnv())
|
|
fmt.Println("config: GiteaTokenEnv: ", c.GetGitTeaTokenEnv())
|
|
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())
|
|
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())
|
|
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("config: EnvVariablesShowAllFlag: ", c.GetEnvShowAllFlag())
|
|
fmt.Println("config: EnvVariablesKey: ", c.GetEnvKey())
|
|
fmt.Println("config: EnvVariablesValue: ", c.GetEnvValue())
|
|
fmt.Println("config: EnvVariablesDeleteFlag: ", c.GetEnvDeleteFlag())
|
|
fmt.Println("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -")
|
|
|
|
}
|