mirror of
https://github.com/outbackdingo/ghorg.git
synced 2026-01-27 10:19:03 +00:00
Add env only for reclone commands (#335)
This commit is contained in:
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
## [1.9.8] - unreleased
|
||||
### Added
|
||||
- Examples command; thanks @MaxG87
|
||||
- GHORG_RECLONE_ENV_CONFIG_ONLY; thanks @vlcinsky
|
||||
### Changed
|
||||
### Deprecated
|
||||
### Removed
|
||||
|
||||
@@ -49,6 +49,10 @@ func reCloneFunc(cmd *cobra.Command, argz []string) {
|
||||
os.Setenv("GHORG_RECLONE_QUIET", "true")
|
||||
}
|
||||
|
||||
if cmd.Flags().Changed("env-config-only") {
|
||||
os.Setenv("GHORG_RECLONE_ENV_CONFIG_ONLY", "true")
|
||||
}
|
||||
|
||||
path := configs.GhorgReCloneLocation()
|
||||
yamlBytes, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
@@ -164,18 +168,20 @@ func runReClone(rc ReClone) {
|
||||
os.Setenv("GHORG_RECLONE_RUNNING", "true")
|
||||
defer os.Setenv("GHORG_RECLONE_RUNNING", "false")
|
||||
|
||||
// have to unset all ghorg envs because root command will set them on initialization of ghorg cmd
|
||||
for _, e := range os.Environ() {
|
||||
keyValue := strings.SplitN(e, "=", 2)
|
||||
env := keyValue[0]
|
||||
ghorgEnv := strings.HasPrefix(env, "GHORG_")
|
||||
if os.Getenv("GHORG_RECLONE_ENV_CONFIG_ONLY") == "false" {
|
||||
// have to unset all ghorg envs because root command will set them on initialization of ghorg cmd
|
||||
for _, e := range os.Environ() {
|
||||
keyValue := strings.SplitN(e, "=", 2)
|
||||
env := keyValue[0]
|
||||
ghorgEnv := strings.HasPrefix(env, "GHORG_")
|
||||
|
||||
// skip global flags and reclone flags which are set in the conf.yaml
|
||||
if env == "GHORG_COLOR" || env == "GHORG_CONFIG" || env == "GHORG_RECLONE_VERBOSE" || env == "GHORG_RECLONE_QUIET" || env == "GHORG_RECLONE_PATH" || env == "GHORG_RECLONE_RUNNING" {
|
||||
continue
|
||||
}
|
||||
if ghorgEnv {
|
||||
os.Unsetenv(env)
|
||||
// skip global flags and reclone flags which are set in the conf.yaml
|
||||
if env == "GHORG_COLOR" || env == "GHORG_CONFIG" || env == "GHORG_RECLONE_VERBOSE" || env == "GHORG_RECLONE_QUIET" || env == "GHORG_RECLONE_PATH" || env == "GHORG_RECLONE_RUNNING" {
|
||||
continue
|
||||
}
|
||||
if ghorgEnv {
|
||||
os.Unsetenv(env)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ var (
|
||||
ghorgReCloneVerbose bool
|
||||
ghorgReCloneQuiet bool
|
||||
ghorgReCloneList bool
|
||||
ghorgReCloneEnvConfigOnly bool
|
||||
noToken bool
|
||||
quietMode bool
|
||||
args []string
|
||||
@@ -139,6 +140,8 @@ func getOrSetDefaults(envVar string) {
|
||||
os.Setenv(envVar, "false")
|
||||
case "GHORG_RECLONE_VERBOSE":
|
||||
os.Setenv(envVar, "false")
|
||||
case "GHORG_RECLONE_ENV_CONFIG_ONLY":
|
||||
os.Setenv(envVar, "false")
|
||||
case "GHORG_RECLONE_QUIET":
|
||||
os.Setenv(envVar, "false")
|
||||
case "GHORG_COLOR":
|
||||
@@ -223,6 +226,7 @@ func InitConfig() {
|
||||
getOrSetDefaults("GHORG_INSECURE_GITEA_CLIENT")
|
||||
getOrSetDefaults("GHORG_BACKUP")
|
||||
getOrSetDefaults("GHORG_RECLONE_VERBOSE")
|
||||
getOrSetDefaults("GHORG_RECLONE_ENV_CONFIG_ONLY")
|
||||
getOrSetDefaults("GHORG_RECLONE_QUIET")
|
||||
getOrSetDefaults("GHORG_CONCURRENCY")
|
||||
getOrSetDefaults("GHORG_INCLUDE_SUBMODULES")
|
||||
@@ -318,6 +322,7 @@ func init() {
|
||||
reCloneCmd.Flags().BoolVar(&ghorgReCloneVerbose, "verbose", false, "GHORG_RECLONE_VERBOSE - Verbose logging output")
|
||||
reCloneCmd.Flags().BoolVar(&ghorgReCloneQuiet, "quiet", false, "GHORG_RECLONE_QUIET - Quiet logging output")
|
||||
reCloneCmd.Flags().BoolVar(&ghorgReCloneList, "list", false, "Prints reclone commands and optional descriptions to stdout then will exit 0. Does not obsfucate tokens, and is only available as a commandline argument")
|
||||
reCloneCmd.Flags().BoolVar(&ghorgReCloneEnvConfigOnly, "env-config-only", false, "GHORG_RECLONE_ENV_CONFIG_ONLY - Only use environment variables to set the configuration for all reclones.")
|
||||
|
||||
rootCmd.AddCommand(lsCmd, versionCmd, cloneCmd, reCloneCmd, examplesCmd)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user