Skip to content

Commit

Permalink
cli: add new env ACK_RAM_TOOL_VERBOSE for "-v, --verbose"
Browse files Browse the repository at this point in the history
  • Loading branch information
mozillazg committed Feb 23, 2024
1 parent 4b652e4 commit 675bf79
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
18 changes: 10 additions & 8 deletions cmd/ack-ram-tool/main.go
Expand Up @@ -45,27 +45,29 @@ func init() {

rootCmd.PersistentFlags().StringVar(&ctl.GlobalOption.Region, "region-id",
"", "The region to use"+
" (env: \"ACK_RAM_TOOL_REGION_ID\")")
fmt.Sprintf(" (env: %q)", ctl.EnvRegionId))
rootCmd.PersistentFlags().BoolVarP(&ctl.GlobalOption.AssumeYes, "assume-yes", "y", false,
"Automatic yes to prompts; assume \"yes\" as answer to all prompts and run non-interactively"+
" (env: \"ACK_RAM_TOOL_ASSUME_YES\")")
fmt.Sprintf(" (env: %q)", ctl.EnvAssumeYes))
rootCmd.PersistentFlags().StringVar(&ctl.GlobalOption.CredentialFilePath, "profile-file", "",
"Path to credential file (default: ~/.aliyun/config.json or ~/.alibabacloud/credentials)"+
" (env: \"ACK_RAM_TOOL_PROFILE_FILE\")")
fmt.Sprintf(" (env: %q)", ctl.EnvProfileFile))
rootCmd.PersistentFlags().StringVar(&ctl.GlobalOption.ProfileName, "profile-name", "",
"using this named profile when parse credentials from config.json of aliyun cli"+
" (env: \"ACK_RAM_TOOL_PROFIL_ENAME\")")
fmt.Sprintf(" (env: %q)", ctl.EnvProfileName))
rootCmd.PersistentFlags().BoolVar(&ctl.GlobalOption.IgnoreEnv,
"ignore-env-credentials", false, "don't try to parse credentials from environment variables"+
" (env: \"ACK_RAM_TOOL_IGNORE_ENV_CREDENTIALS\")")
fmt.Sprintf(" (env: %q)", ctl.EnvIgnoreEnvCredentials))
rootCmd.PersistentFlags().BoolVar(&ctl.GlobalOption.IgnoreAliyuncliConfig,
"ignore-aliyun-cli-credentials", false, "don't try to parse credentials from config.json of aliyun cli"+
" (env: \"ACK_RAM_TOOL_IGNORE_ALIYUN_CLI_CREDENTIALS\")")
fmt.Sprintf(" (env: %q)", ctl.EnvIgnoreAliyunCliCredentials))
rootCmd.PersistentFlags().StringVar(&ctl.GlobalOption.LogLevel, "log-level", "",
fmt.Sprintf("log level: info, debug, error (default \"%s\")", ctl.DefaultLogLevel)+
" (env: \"ACK_RAM_TOOL_LOG_LEVEL\")")
fmt.Sprintf(" (env: %q)", ctl.EnvLogLevel))
//rootCmd.PersistentFlags().BoolVarP(&ctl.GlobalOption.InsecureSkipTLSVerify, "insecure-skip-tls-verify", "", false, "Skips the validity check for the server's certificate")
rootCmd.PersistentFlags().BoolVarP(&ctl.GlobalOption.Verbose, "verbose", "v", false, "Make the operation more talkative")
rootCmd.PersistentFlags().BoolVarP(&ctl.GlobalOption.Verbose, "verbose", "v", false,
"Make the operation more talkative"+
fmt.Sprintf(" (env: %q)", ctl.EnvVerbose))
}

func main() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/ctl/common/client.go
Expand Up @@ -124,7 +124,7 @@ func getCredential(opt getCredentialOption) (provider.CredentialsProvider, error

acli, err := aliyuncli.NewCredentialHelper(aliyuncliConfigFilePath, aliyuncliProfileName, opt.stsEndpoint)
if err == nil && acli != nil {
log.Logger.Debugf("get credentials from aliyun cli (%s) with profile name %s",
log.Logger.Debugf("try to get credentials from aliyun cli (%s) with profile name %s",
utils.ShortHomePath(aliyuncliConfigFilePath), acli.ProfileName())
return acli.GetCredentials()
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/ctl/global.go
Expand Up @@ -16,6 +16,7 @@ const (
EnvIgnoreAliyunCliCredentials = "ACK_RAM_TOOL_IGNORE_ALIYUN_CLI_CREDENTIALS" // #nosec G101
EnvLogLevel = "ACK_RAM_TOOL_LOG_LEVEL"
EnvRegionId = "ACK_RAM_TOOL_REGION_ID"
EnvVerbose = "ACK_RAM_TOOL_VERBOSE"

DefaultRegion = ""
DefaultLogLevel = "info"
Expand Down Expand Up @@ -63,6 +64,9 @@ func (g *globalOption) UpdateValues() {
if v, err := strconv.ParseBool(os.Getenv(EnvIgnoreAliyunCliCredentials)); err == nil && v {
g.IgnoreAliyuncliConfig = true
}
if v, err := strconv.ParseBool(os.Getenv(EnvVerbose)); err == nil && v {
g.Verbose = true
}
if g.LogLevel == "" {
g.LogLevel = os.Getenv(EnvLogLevel)
}
Expand Down

0 comments on commit 675bf79

Please sign in to comment.