From 5477abc135856d46f98a2d4abad137dfef3fa58f Mon Sep 17 00:00:00 2001 From: Aaron Turner Date: Tue, 20 Aug 2024 17:04:41 -0700 Subject: [PATCH] basic xonsh support - Support eval/exec commands. - Tweak codecov.yaml Refs: #1018 --- .codecov.yml | 2 +- cmd/aws-sso/eval_cmd.go | 6 ++++++ cmd/aws-sso/exec_cmd.go | 11 ++++++++--- docs/commands.md | 8 ++++++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/.codecov.yml b/.codecov.yml index 1cac34aa..ef6a7c3a 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -9,4 +9,4 @@ coverage: ignore: - "cmd/**/*" - + - "cmd" diff --git a/cmd/aws-sso/eval_cmd.go b/cmd/aws-sso/eval_cmd.go index 1c48befd..4597123b 100644 --- a/cmd/aws-sso/eval_cmd.go +++ b/cmd/aws-sso/eval_cmd.go @@ -98,6 +98,8 @@ func (cc *EvalCmd) Run(ctx *RunContext) error { } else if runtime.GOOS == "windows" { // powershell Invoke-Expression https://github.com/synfinatic/aws-sso-cli/issues/188 fmt.Printf("$Env:%s = \"%s\"\r\n", k, v) + } else if os.Getenv("XONSH_VERSION") != "" { + fmt.Printf("$%s = '%s'\n", k, v) } else { return fmt.Errorf("%s", "invalid or unsupported shell. Please file a bug!") } @@ -139,6 +141,9 @@ func unsetEnvVars(ctx *RunContext) error { } else if runtime.GOOS == "windows" { // PowerShell fmt.Printf("$Env:%s = \"\"\r\n", e) + } else if os.Getenv("XONSH_VERSION") != "" { + // xonsh behaves like python + fmt.Printf("del $%s\n", e) } else { return fmt.Errorf("invalid or unsupported shell. Please file a bug!") } @@ -160,5 +165,6 @@ func isBashLike() bool { return true } } + return false } diff --git a/cmd/aws-sso/exec_cmd.go b/cmd/aws-sso/exec_cmd.go index 837273ca..71bbc08c 100644 --- a/cmd/aws-sso/exec_cmd.go +++ b/cmd/aws-sso/exec_cmd.go @@ -55,9 +55,14 @@ func (cc *ExecCmd) Run(ctx *RunContext) error { log.Fatal("Unable to continue", "error", err.Error()) } - if runtime.GOOS == "windows" && ctx.Cli.Exec.Cmd == "" { - // Windows doesn't set $SHELL, so default to CommandPrompt - ctx.Cli.Exec.Cmd = "cmd.exe" + if ctx.Cli.Exec.Cmd == "" { + if runtime.GOOS == "windows" { + // Windows doesn't set $SHELL, so default to CommandPrompt + ctx.Cli.Exec.Cmd = "cmd.exe" + } else if os.Getenv("XONSH_VERSION") != "" { + // Xonsh doesn't set $SHELL, so default to xonsh + ctx.Cli.Exec.Cmd = "xonsh" + } } sci := NewSelectCliArgs(ctx.Cli.Exec.Arn, ctx.Cli.Exec.AccountId, ctx.Cli.Exec.Role, ctx.Cli.Exec.Profile) diff --git a/docs/commands.md b/docs/commands.md index 03b10f39..c176f23a 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -109,6 +109,14 @@ you can write the variable to a file: `aws-sso eval >~/.devcontainer/devcontainer.env` +Shells supported by `eval`: + + * bash + * fish + * zonsh + * zsh + * Windows PowerShell + Flags: * `--arn `, `-a` -- ARN of role to assume