diff --git a/api/apiuser.go b/api/apiuser.go index 5f9bb31..26c9d7b 100644 --- a/api/apiuser.go +++ b/api/apiuser.go @@ -14,13 +14,19 @@ import ( type UserResponse struct { Data struct { - Username string `json:"username"` - Email string `json:"email"` - FirstName string `json:"first_name"` - LastName string `json:"last_name"` - ID string `json:"id"` - Pin string `json:"pin"` - Subject struct { + Username string `json:"username"` + Email string `json:"email"` + FirstName string `json:"first_name"` + LastName string `json:"last_name"` + Role string `json:"role"` + IsStaff bool `json:"is_staff"` + IsSuperUser bool `json:"is_superuser"` + DateJoined string `json:"date_joined"` + ID string `json:"id"` + IsActive bool `json:"is_active"` + LastLogin string `json:"last_login"` + Pin string `json:"pin"` + Subject struct { ID string `json:"id"` } `json:"subject"` } `json:"data"` diff --git a/cmd/user.go b/cmd/user.go index 6b51dd6..5d2ff73 100644 --- a/cmd/user.go +++ b/cmd/user.go @@ -9,6 +9,8 @@ import ( "github.com/spf13/cobra" ) +var all bool + // ---------------------------------------------- // user command // ---------------------------------------------- @@ -34,23 +36,42 @@ func user() { } if userResponse != nil { - data := []string{ - userResponse.Data.Username, - userResponse.Data.Email, - userResponse.Data.FirstName, - userResponse.Data.LastName, - userResponse.Data.ID, - userResponse.Data.Pin, - userResponse.Data.Subject.ID, - } + switch { + case all: + allUserDataFmt := fmt.Sprintf("username: %s\nemail: %s\nfirst name: %s\nlast name: %s\nrole: %s\nis staff: %t\nis superuser: %t\ndate joined: %s\nid: %s\nisactive: %t\nlast login: %s\npin: %s\nsubject id: %s", + userResponse.Data.Username, + userResponse.Data.Email, + userResponse.Data.FirstName, + userResponse.Data.LastName, + userResponse.Data.Role, + userResponse.Data.IsStaff, + userResponse.Data.IsSuperUser, + userResponse.Data.DateJoined, + userResponse.Data.ID, + userResponse.Data.IsActive, + userResponse.Data.LastLogin, + userResponse.Data.Pin, + userResponse.Data.Subject.ID) + fmt.Println(allUserDataFmt) + default: + userData := []string{ + userResponse.Data.Username, + userResponse.Data.Email, + userResponse.Data.FirstName, + userResponse.Data.LastName, + userResponse.Data.ID, + userResponse.Data.Pin, + userResponse.Data.Subject.ID, + } - table := tablewriter.NewWriter(os.Stdout) - table.SetHeader([]string{"Username", "Email", "First Name", "Last Name", "ID", "Pin", "Subject ID"}) - table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false}) - table.SetCenterSeparator("|") - table.Append(data) + table := tablewriter.NewWriter(os.Stdout) + table.SetHeader([]string{"Username", "Email", "First Name", "Last Name", "ID", "Pin", "Subject ID"}) + table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false}) + table.SetCenterSeparator("|") + table.Append(userData) - table.Render() + table.Render() + } } } @@ -60,4 +81,5 @@ func user() { func init() { rootCmd.AddCommand(userCmd) + userCmd.Flags().BoolVarP(&all, "all", "a", false, "list all user parameters") }