Skip to content

Commit

Permalink
basic xonsh support
Browse files Browse the repository at this point in the history
- Support eval/exec commands.
- Tweak codecov.yaml

Refs: #1018
  • Loading branch information
synfinatic committed Aug 21, 2024
1 parent 4d84ccc commit 5477abc
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)

Check warning on line 102 in cmd/aws-sso/eval_cmd.go

View check run for this annotation

Codecov / codecov/patch

cmd/aws-sso/eval_cmd.go#L101-L102

Added lines #L101 - L102 were not covered by tests
} 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") != "" {

Check warning on line 144 in cmd/aws-sso/eval_cmd.go

View check run for this annotation

Codecov / codecov/patch

cmd/aws-sso/eval_cmd.go#L144

Added line #L144 was not covered by tests
// xonsh behaves like python
fmt.Printf("del $%s\n", e)

Check warning on line 146 in cmd/aws-sso/eval_cmd.go

View check run for this annotation

Codecov / codecov/patch

cmd/aws-sso/eval_cmd.go#L146

Added line #L146 was not covered by tests
} 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" {

Check warning on line 59 in cmd/aws-sso/exec_cmd.go

View check run for this annotation

Codecov / codecov/patch

cmd/aws-sso/exec_cmd.go#L58-L59

Added lines #L58 - L59 were not covered by tests
// Windows doesn't set $SHELL, so default to CommandPrompt
ctx.Cli.Exec.Cmd = "cmd.exe"
} else if os.Getenv("XONSH_VERSION") != "" {

Check warning on line 62 in cmd/aws-sso/exec_cmd.go

View check run for this annotation

Codecov / codecov/patch

cmd/aws-sso/exec_cmd.go#L61-L62

Added lines #L61 - L62 were not covered by tests
// Xonsh doesn't set $SHELL, so default to xonsh
ctx.Cli.Exec.Cmd = "xonsh"

Check warning on line 64 in cmd/aws-sso/exec_cmd.go

View check run for this annotation

Codecov / codecov/patch

cmd/aws-sso/exec_cmd.go#L64

Added line #L64 was not covered by tests
}
}

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 5477abc

Please sign in to comment.