From ddb189e140ee8575d44d728704c065cc54475838 Mon Sep 17 00:00:00 2001 From: Dan O'Neill Date: Fri, 8 Dec 2023 19:07:29 -0800 Subject: [PATCH 1/3] add more response params --- api/apiuser.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) 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"` From 3edc70a7dfeb0269813c639c7aae92b6a3083827 Mon Sep 17 00:00:00 2001 From: Dan O'Neill Date: Fri, 8 Dec 2023 19:12:10 -0800 Subject: [PATCH 2/3] add all flag --- cmd/user.go | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/cmd/user.go b/cmd/user.go index 6b51dd6..644f4b1 100644 --- a/cmd/user.go +++ b/cmd/user.go @@ -34,23 +34,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() + } } } From d7906bec6fb31f477c68b68bce7d080eecb2e21e Mon Sep 17 00:00:00 2001 From: Dan O'Neill Date: Fri, 8 Dec 2023 19:18:16 -0800 Subject: [PATCH 3/3] add flag to user command --- cmd/user.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/user.go b/cmd/user.go index 644f4b1..5d2ff73 100644 --- a/cmd/user.go +++ b/cmd/user.go @@ -9,6 +9,8 @@ import ( "github.com/spf13/cobra" ) +var all bool + // ---------------------------------------------- // user command // ---------------------------------------------- @@ -79,4 +81,5 @@ func user() { func init() { rootCmd.AddCommand(userCmd) + userCmd.Flags().BoolVarP(&all, "all", "a", false, "list all user parameters") }