diff options
Diffstat (limited to 'go/internal/command/discover/discover.go')
-rw-r--r-- | go/internal/command/discover/discover.go | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/go/internal/command/discover/discover.go b/go/internal/command/discover/discover.go index 63a7a32..ab04cbd 100644 --- a/go/internal/command/discover/discover.go +++ b/go/internal/command/discover/discover.go @@ -2,9 +2,12 @@ package discover import ( "fmt" + "io" + "os" "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/commandargs" "gitlab.com/gitlab-org/gitlab-shell/go/internal/config" + "gitlab.com/gitlab-org/gitlab-shell/go/internal/gitlabnet/discover" ) type Command struct { @@ -12,6 +15,38 @@ type Command struct { Args *commandargs.CommandArgs } +var ( + output io.Writer = os.Stdout +) + func (c *Command) Execute() error { - return fmt.Errorf("No feature is implemented yet") + response, err := c.getUserInfo() + if err != nil { + return fmt.Errorf("Failed to get username: %v", err) + } + + if response.IsAnonymous() { + fmt.Fprintf(output, "Welcome to GitLab, Anonymous!\n") + } else { + fmt.Fprintf(output, "Welcome to GitLab, @%s!\n", response.Username) + } + + return nil +} + +func (c *Command) getUserInfo() (*discover.Response, error) { + client, err := discover.NewClient(c.Config) + if err != nil { + return nil, err + } + + if c.Args.GitlabKeyId != "" { + return client.GetByKeyId(c.Args.GitlabKeyId) + } else if c.Args.GitlabUsername != "" { + return client.GetByUsername(c.Args.GitlabUsername) + } else { + // There was no 'who' information, this matches the ruby error + // message. + return nil, fmt.Errorf("who='' is invalid") + } } |