list.go 871 B

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