Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Commit

Permalink
Enable config dir setting via env variable (#611)
Browse files Browse the repository at this point in the history
Thanks to @kampka!
  • Loading branch information
kampka committed Mar 4, 2021
1 parent 82bfcd4 commit d479e54
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions commands/info/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ func getEnvironmentVariables() map[string]string {
vars := []string{
"GSCTL_CAFILE",
"GSCTL_CAPATH",
"GSCTL_CONFIG_DIR",
"GSCTL_DISABLE_CMDLINE_TRACKING",
"GSCTL_DISABLE_COLORS",
"GSCTL_ENDPOINT",
Expand Down
8 changes: 7 additions & 1 deletion commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,14 @@ func init() {
// if it exists.
tokenFromEnv := os.Getenv("GSCTL_AUTH_TOKEN")

defaultConfigDir := config.DefaultConfigDirPath
configDirFromEnv := os.Getenv("GSCTL_CONFIG_DIR")
if (configDirFromEnv != "") {
defaultConfigDir = configDirFromEnv
}

RootCommand.PersistentFlags().StringVarP(&flags.Token, "auth-token", "", tokenFromEnv, "Authorization token to use")
RootCommand.PersistentFlags().StringVarP(&flags.ConfigDirPath, "config-dir", "", config.DefaultConfigDirPath, "Configuration directory path to use")
RootCommand.PersistentFlags().StringVarP(&flags.ConfigDirPath, "config-dir", "", defaultConfigDir, "Configuration directory path to use")
RootCommand.PersistentFlags().BoolVarP(&flags.Verbose, "verbose", "v", false, "Print more information")
RootCommand.PersistentFlags().BoolVarP(&flags.SilenceHTTPEndpointWarning, "silence-http-endpoint-warning", "", false, "Dont't print warnings when deliberately using an insecure HTTP endpoint")
RootCommand.Flags().Bool("version", false, version.Command.Short)
Expand Down

0 comments on commit d479e54

Please sign in to comment.