diff --git a/README.md b/README.md index 1b65b1d..e09f3d2 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,10 @@ AWS_ACCESS_KEY_ID=myaccesskey AWS_ACCESS_KEY=myaccesskey AWS_SECRET_KEY=mysecretkey +# Now the prompt command can tell you which env is set +$ awsenv prompt +demoenv + # Lets try to unlock with a wrong password $ awsenv lock $ awsenv unlock diff --git a/cmdPrompt.go b/cmdPrompt.go new file mode 100644 index 0000000..0faa5af --- /dev/null +++ b/cmdPrompt.go @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" +) + +func getCmdPrompt() *cobra.Command { + cmd := cobra.Command{ + Use: "prompt", + Short: "echos the name of the currently set env for use in prompts", + Run: actionCmdPrompt, + } + return &cmd +} + +func actionCmdPrompt(cmd *cobra.Command, args []string) { + for k, v := range awsCredentials.Credentials { + if v.AWSAccessKeyID == os.Getenv("AWS_ACCESS_KEY") { + fmt.Printf(k) + } + } +} diff --git a/main.go b/main.go index 9f77d0a..6eaa5a1 100644 --- a/main.go +++ b/main.go @@ -94,6 +94,7 @@ func main() { getCmdList(), getCmdLock(), getCmdShell(), + getCmdPrompt(), getCmdUnlock(), getCmdVersion(), )