Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add self command (and whoami alias) #377

Merged
merged 2 commits into from
Aug 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
### To be Released

* [env-set] Advise to restart after setting the environment #373
* [self] Add `self` (and `whoami` alias) #350
* Better error message if 401 Unauthorized #352

### 1.9.0
Expand Down
2 changes: 2 additions & 0 deletions cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ var (
LoginCommand,
LogoutCommand,
SignUpCommand,
selfCommand,
whoamiCommand, // `self` alias

// Version
UpdateCommand,
Expand Down
32 changes: 32 additions & 0 deletions cmd/self.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cmd

import (
"github.com/Scalingo/cli/config"
"github.com/Scalingo/cli/io"
"github.com/urfave/cli"
)

var (
selfCommand = cli.Command{
Name: "self",
Category: "Global",
Usage: "Get the logged in profile",
Description: "Returns the logged in profile and print its username. Comes in handy when owning multiple accounts.",
Before: AuthenticateHook,
Action: func(c *cli.Context) {
if config.AuthenticatedUser != nil {
io.Statusf("You are logged in as %s (%s)\n", config.AuthenticatedUser.Username, config.AuthenticatedUser.Email)
return
}
io.Status("Currently unauthenticated")
},
}
whoamiCommand = cli.Command{
Name: "whoami",
Category: selfCommand.Category,
Usage: selfCommand.Usage,
Description: selfCommand.Description,
Before: selfCommand.Before,
Action: selfCommand.Action,
}
)