Skip to content

Commit

Permalink
Merge pull request #8 from doneill/task/JDO-25-user-all
Browse files Browse the repository at this point in the history
User all Flag
  • Loading branch information
doneill committed Dec 9, 2023
2 parents cf08e9c + d7906be commit bed476a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 22 deletions.
20 changes: 13 additions & 7 deletions api/apiuser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
52 changes: 37 additions & 15 deletions cmd/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/spf13/cobra"
)

var all bool

// ----------------------------------------------
// user command
// ----------------------------------------------
Expand All @@ -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()
}
}
}

Expand All @@ -60,4 +81,5 @@ func user() {

func init() {
rootCmd.AddCommand(userCmd)
userCmd.Flags().BoolVarP(&all, "all", "a", false, "list all user parameters")
}

0 comments on commit bed476a

Please sign in to comment.