Skip to content

Commit 1950a5c

Browse files
committed
Merge branch 'master' of https://github.com/gabrie30/ghorg
2 parents 98516d5 + 4c3e68c commit 1950a5c

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
## [1.9.8] - 8/25/23
77
### Added
88
- Examples command; thanks @MaxG87
9+
- GHORG_RECLONE_ENV_CONFIG_ONLY; thanks @vlcinsky
910
### Changed
1011
### Deprecated
1112
### Removed

cmd/reclone.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ func reCloneFunc(cmd *cobra.Command, argz []string) {
4949
os.Setenv("GHORG_RECLONE_QUIET", "true")
5050
}
5151

52+
if cmd.Flags().Changed("env-config-only") {
53+
os.Setenv("GHORG_RECLONE_ENV_CONFIG_ONLY", "true")
54+
}
55+
5256
path := configs.GhorgReCloneLocation()
5357
yamlBytes, err := ioutil.ReadFile(path)
5458
if err != nil {
@@ -164,18 +168,20 @@ func runReClone(rc ReClone) {
164168
os.Setenv("GHORG_RECLONE_RUNNING", "true")
165169
defer os.Setenv("GHORG_RECLONE_RUNNING", "false")
166170

167-
// have to unset all ghorg envs because root command will set them on initialization of ghorg cmd
168-
for _, e := range os.Environ() {
169-
keyValue := strings.SplitN(e, "=", 2)
170-
env := keyValue[0]
171-
ghorgEnv := strings.HasPrefix(env, "GHORG_")
171+
if os.Getenv("GHORG_RECLONE_ENV_CONFIG_ONLY") == "false" {
172+
// have to unset all ghorg envs because root command will set them on initialization of ghorg cmd
173+
for _, e := range os.Environ() {
174+
keyValue := strings.SplitN(e, "=", 2)
175+
env := keyValue[0]
176+
ghorgEnv := strings.HasPrefix(env, "GHORG_")
172177

173-
// skip global flags and reclone flags which are set in the conf.yaml
174-
if env == "GHORG_COLOR" || env == "GHORG_CONFIG" || env == "GHORG_RECLONE_VERBOSE" || env == "GHORG_RECLONE_QUIET" || env == "GHORG_RECLONE_PATH" || env == "GHORG_RECLONE_RUNNING" {
175-
continue
176-
}
177-
if ghorgEnv {
178-
os.Unsetenv(env)
178+
// skip global flags and reclone flags which are set in the conf.yaml
179+
if env == "GHORG_COLOR" || env == "GHORG_CONFIG" || env == "GHORG_RECLONE_VERBOSE" || env == "GHORG_RECLONE_QUIET" || env == "GHORG_RECLONE_PATH" || env == "GHORG_RECLONE_RUNNING" {
180+
continue
181+
}
182+
if ghorgEnv {
183+
os.Unsetenv(env)
184+
}
179185
}
180186
}
181187

cmd/root.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ var (
6060
ghorgReCloneVerbose bool
6161
ghorgReCloneQuiet bool
6262
ghorgReCloneList bool
63+
ghorgReCloneEnvConfigOnly bool
6364
noToken bool
6465
quietMode bool
6566
args []string
@@ -139,6 +140,8 @@ func getOrSetDefaults(envVar string) {
139140
os.Setenv(envVar, "false")
140141
case "GHORG_RECLONE_VERBOSE":
141142
os.Setenv(envVar, "false")
143+
case "GHORG_RECLONE_ENV_CONFIG_ONLY":
144+
os.Setenv(envVar, "false")
142145
case "GHORG_RECLONE_QUIET":
143146
os.Setenv(envVar, "false")
144147
case "GHORG_COLOR":
@@ -223,6 +226,7 @@ func InitConfig() {
223226
getOrSetDefaults("GHORG_INSECURE_GITEA_CLIENT")
224227
getOrSetDefaults("GHORG_BACKUP")
225228
getOrSetDefaults("GHORG_RECLONE_VERBOSE")
229+
getOrSetDefaults("GHORG_RECLONE_ENV_CONFIG_ONLY")
226230
getOrSetDefaults("GHORG_RECLONE_QUIET")
227231
getOrSetDefaults("GHORG_CONCURRENCY")
228232
getOrSetDefaults("GHORG_INCLUDE_SUBMODULES")
@@ -318,6 +322,7 @@ func init() {
318322
reCloneCmd.Flags().BoolVar(&ghorgReCloneVerbose, "verbose", false, "GHORG_RECLONE_VERBOSE - Verbose logging output")
319323
reCloneCmd.Flags().BoolVar(&ghorgReCloneQuiet, "quiet", false, "GHORG_RECLONE_QUIET - Quiet logging output")
320324
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")
325+
reCloneCmd.Flags().BoolVar(&ghorgReCloneEnvConfigOnly, "env-config-only", false, "GHORG_RECLONE_ENV_CONFIG_ONLY - Only use environment variables to set the configuration for all reclones.")
321326

322327
rootCmd.AddCommand(lsCmd, versionCmd, cloneCmd, reCloneCmd, examplesCmd)
323328
}

0 commit comments

Comments
 (0)