Skip to content

Commit

Permalink
remind101#16 use PathSeparator in combination with GOOS to confirm Po…
Browse files Browse the repository at this point in the history
…werShell

usage on Windows
  • Loading branch information
Yunspace committed Sep 6, 2017
1 parent 4fdc6d6 commit 5e765b7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ func init() {
func defaultFormat() string {
switch runtime.GOOS {
case "windows":
return "powershell"
if os.PathSeparator == '\\' {
return "powershell"
}
fallthrough
default:
return "bash"
}
Expand Down Expand Up @@ -92,7 +95,7 @@ func main() {
if len(args) == 0 {
switch *format {
case "powershell":
printWindowsCredentials(role, creds)
printPowerShellCredentials(role, creds)
case "bash":
printCredentials(role, creds)
default:
Expand Down Expand Up @@ -140,9 +143,9 @@ func printCredentials(role string, creds *credentials.Value) {
fmt.Printf("# eval $(%s)\n", strings.Join(os.Args, " "))
}

// printWindowsCredentials prints the credentials in a way that can easily be sourced
// printPowerShellCredentials prints the credentials in a way that can easily be sourced
// with Windows powershell using Invoke-Expression.
func printWindowsCredentials(role string, creds *credentials.Value) {
func printPowerShellCredentials(role string, creds *credentials.Value) {
fmt.Printf("$env:AWS_ACCESS_KEY_ID=\"%s\"\n", creds.AccessKeyID)
fmt.Printf("$env:AWS_SECRET_ACCESS_KEY=\"%s\"\n", creds.SecretAccessKey)
fmt.Printf("$env:AWS_SESSION_TOKEN=\"%s\"\n", creds.SessionToken)
Expand Down

0 comments on commit 5e765b7

Please sign in to comment.