Skip to content

Commit

Permalink
Merge pull request #1033 from synfinatic/xonsh
Browse files Browse the repository at this point in the history
basic xonsh support
  • Loading branch information
synfinatic authored Aug 21, 2024
2 parents 4d84ccc + 5477abc commit 527e36f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ coverage:

ignore:
- "cmd/**/*"

- "cmd"
6 changes: 6 additions & 0 deletions cmd/aws-sso/eval_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
}
Expand Down Expand Up @@ -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!")
}
Expand All @@ -160,5 +165,6 @@ func isBashLike() bool {
return true
}
}

return false
}
11 changes: 8 additions & 3 deletions cmd/aws-sso/exec_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ you can write the variable to a file:

`aws-sso eval <args> >~/.devcontainer/devcontainer.env`

Shells supported by `eval`:

* bash
* fish
* zonsh
* zsh
* Windows PowerShell

Flags:

* `--arn <arn>`, `-a` -- ARN of role to assume
Expand Down

0 comments on commit 527e36f

Please sign in to comment.