Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/#37 add quiet flag #41

Merged
merged 2 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ By default, the tool will prompt you to interactively select which cluster, serv
| `--task` | `-t` | Specify the ECS Task ID | N/A |
| `--container` | `-u` | Specify the container name in the ECS Task (if task only has one container this will selected by default) | N/A |
| `--cmd` | `-c` | Specify the command to be run on the container (default will change depending on OS family). | `/bin/sh`,`powershell.exe` |
| `--forward` | `-f` | Toggle port-forwarding to the container (Remote port will be taken from task/container definitions) | `false` |
| `--forward` | `-f` | Port-forward to the container (Remote port will be taken from task/container definitions) | `false` |
| `--local-port` | `-l` | Specify local port to forward (will prompt if not specified) | N/A |
| `--profile` | `-p` | Specify the profile to load the credentials | `default` |
| `--region` | `-r` | Specify the AWS region to run in | N/A |
| `--quiet` | `-q` | Disable output detailing the Cluster/Service/Task information | `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
2 changes: 2 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func init() {
rootCmd.PersistentFlags().StringP("container", "u", "", "Container name")
rootCmd.PersistentFlags().BoolP("forward", "f", false, "Port Forward")
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")

viper.BindPFlag("cmd", rootCmd.PersistentFlags().Lookup("cmd"))
viper.BindPFlag("profile", rootCmd.PersistentFlags().Lookup("profile"))
Expand All @@ -103,4 +104,5 @@ func init() {
viper.BindPFlag("container", rootCmd.PersistentFlags().Lookup("container"))
viper.BindPFlag("forward", rootCmd.PersistentFlags().Lookup("forward"))
viper.BindPFlag("local-port", rootCmd.PersistentFlags().Lookup("local-port"))
viper.BindPFlag("quiet", rootCmd.PersistentFlags().Lookup("quiet"))
}
6 changes: 4 additions & 2 deletions internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ func (e *App) executeCommand() error {
}

// Print Cluster/Service/Task information to the console
fmt.Printf("\nCluster: %v | Service: %v | Task: %s | Cmd: %s", Cyan(e.cluster), Magenta(e.service), Green(strings.Split(*e.task.TaskArn, "/")[2]), Yellow(command))
fmt.Printf("\nConnecting to container %v\n", Yellow(*e.container.Name))
if !viper.GetBool("quiet") {
fmt.Printf("\nCluster: %v | Service: %v | Task: %s | Cmd: %s", Cyan(e.cluster), Magenta(e.service), Green(strings.Split(*e.task.TaskArn, "/")[2]), Yellow(command))
fmt.Printf("\nConnecting to container %v\n", Yellow(*e.container.Name))
}

// Execute the session-manager-plugin with our task details
err = runCommand("session-manager-plugin", string(execSess), e.region, "StartSession", "", string(targetJson), e.endpoint)
Expand Down
6 changes: 4 additions & 2 deletions internal/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ func (e *App) executeForward() error {
}

// Print Cluster/Service/Task information to the console
fmt.Printf("\nCluster: %v | Service: %v | Task: %s", Cyan(e.cluster), Magenta(e.service), Green(strings.Split(*e.task.TaskArn, "/")[2]))
fmt.Printf("\nPort-forwarding %s:%d -> container %v\n", localPort, *containerPort, Yellow(*e.container.Name))
if !viper.GetBool("quiet") {
fmt.Printf("\nCluster: %v | Service: %v | Task: %s", Cyan(e.cluster), Magenta(e.service), Green(strings.Split(*e.task.TaskArn, "/")[2]))
fmt.Printf("\nPort-forwarding %s:%d -> container %v\n", localPort, *containerPort, Yellow(*e.container.Name))
}

// Execute the session-manager-plugin with our task details
err = runCommand("session-manager-plugin", string(sessJson), e.region, "StartSession", "", string(paramsJson))
Expand Down
Loading