Skip to content

Commit

Permalink
Merge pull request #14 from Andrius521/fix_user_get
Browse files Browse the repository at this point in the history
[CHANGE] command `user get` return current user info if ID is not given
  • Loading branch information
Andrius521 authored Sep 15, 2022
2 parents 7a4415f + 3f33d3c commit 797177c
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions internal/users/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ import (
func (c *Client) Get() *cobra.Command {
var userID int
userGetCmd := &cobra.Command{
Use: `get ID`,
Args: cobra.ExactArgs(1),
Use: `get ID`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
usrID, err := strconv.Atoi(args[0])
if err == nil {
userID = usrID
}
}
return nil
},
Short: "Retrieves information about the current user or a specified user.",
Long: "Returns either information about the current user or information about a specified user. Specified user information is only available if that user shares a project with the current user.",
Example: ` # Gets the current user's information:
Expand All @@ -25,9 +33,6 @@ func (c *Client) Get() *cobra.Command {
cmd.SilenceUsage = true
var user cherrygo.User
var err error
if uID, err := strconv.Atoi(args[0]); err == nil {
userID = uID
}
if userID == 0 {
user, _, err = c.Service.CurrentUser(c.Servicer.GetOptions())
if err != nil {
Expand Down

0 comments on commit 797177c

Please sign in to comment.