list.go 826 B

123456789101112131415161718192021222324252627282930313233343536
  1. package user
  2. import (
  3. "os"
  4. "strconv"
  5. "github.com/gravitl/netmaker/cli/cmd/commons"
  6. "github.com/gravitl/netmaker/cli/functions"
  7. "github.com/guumaster/tablewriter"
  8. "github.com/spf13/cobra"
  9. )
  10. var userListCmd = &cobra.Command{
  11. Use: "list",
  12. Args: cobra.NoArgs,
  13. Short: "List all users",
  14. Long: `List all users`,
  15. Run: func(cmd *cobra.Command, args []string) {
  16. data := functions.ListUsers()
  17. switch commons.OutputFormat {
  18. case commons.JsonOutput:
  19. functions.PrettyPrint(data)
  20. default:
  21. table := tablewriter.NewWriter(os.Stdout)
  22. table.SetHeader([]string{"Name", "SuperAdmin", "Admin"})
  23. for _, d := range *data {
  24. table.Append([]string{d.UserName, strconv.FormatBool(d.IsSuperAdmin), strconv.FormatBool(d.IsAdmin)})
  25. }
  26. table.Render()
  27. }
  28. },
  29. }
  30. func init() {
  31. rootCmd.AddCommand(userListCmd)
  32. }