Skip to content

Commit

Permalink
Updating env population of cli args to be behind a cli flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeforkin authored and tedsmitt committed Oct 9, 2024
1 parent ce9fc68 commit c3beef8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ By default, the tool will prompt you to interactively select which cluster, serv
| `--region` | `-r` | Specify the AWS region to run in | N/A |
| `--quiet` | `-q` | Disable output detailing the Cluster/Service/Task information | `false` |
| `--aws-endpoint-url` | `-e` | Specify the AWS endpoint used for all service requests | N/A |
| `--enable-env` | `-v` | Enable ENV population of cli args | `false` |



The tool also supports AWS Config/Environment Variables for configuration. If you aren't familiar with working on AWS via the CLI, you can read more about how to configure your environment [here](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html).

Expand Down
11 changes: 8 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ Requires pre-existing installation of the session-manager-plugin
fmt.Printf(fmt.Sprintf("%s\n", app.Yellow("The service argument will be ignored when task is specified")))
viper.Set("service", "")
}

if viper.GetBool("enable-env") {
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.AutomaticEnv()
}

return nil
},
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -96,9 +102,7 @@ func init() {
rootCmd.PersistentFlags().StringP("local-port", "l", "", "Local port for use with port forwarding")
rootCmd.PersistentFlags().BoolP("quiet", "q", false, "Do not print cluster and container information")
rootCmd.PersistentFlags().StringP("aws-endpoint-url", "e", "", "AWS Endpoint Url")

viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.AutomaticEnv()
rootCmd.PersistentFlags().BoolP("enable-env", "v", false, "Enable ENV population of cli args")

viper.BindPFlag("cmd", rootCmd.PersistentFlags().Lookup("cmd"))
viper.BindPFlag("profile", rootCmd.PersistentFlags().Lookup("profile"))
Expand All @@ -111,4 +115,5 @@ func init() {
viper.BindPFlag("local-port", rootCmd.PersistentFlags().Lookup("local-port"))
viper.BindPFlag("quiet", rootCmd.PersistentFlags().Lookup("quiet"))
viper.BindPFlag("aws-endpoint-url", rootCmd.PersistentFlags().Lookup("aws-endpoint-url"))
viper.BindPFlag("enable-env", rootCmd.PersistentFlags().Lookup("enable-env"))
}

0 comments on commit c3beef8

Please sign in to comment.