Skip to content

Commit

Permalink
structure user response in markdown table format
Browse files Browse the repository at this point in the history
  • Loading branch information
doneill committed Nov 29, 2023
1 parent e704b08 commit 06e0fb8
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions cmd/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"github.com/doneill/er-cli-go/api"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -33,23 +34,23 @@ func user() {
}

if userResponse != nil {
formattedResponse := 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\npermissions:\n patrol: %v\nmobile tests: %v",
data := []string{
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,
userResponse.Data.Permissions.Patrol,
userResponse.Data.Permissions.MobileTests)
fmt.Println(formattedResponse)
}

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.Render()
}
}

Expand Down

0 comments on commit 06e0fb8

Please sign in to comment.