From 3f33d3cea4107d6c62cacd3d838ef914949861b3 Mon Sep 17 00:00:00 2001 From: Andrius Jucius Date: Thu, 15 Sep 2022 13:53:18 +0300 Subject: [PATCH] [CHANGE] command `user get` return current user info if ID is not given --- internal/users/get.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/internal/users/get.go b/internal/users/get.go index 722eac6..826c20e 100644 --- a/internal/users/get.go +++ b/internal/users/get.go @@ -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: @@ -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 {