list.go 698 B

123456789101112131415161718192021222324252627282930
  1. package user
  2. import (
  3. "os"
  4. "strconv"
  5. "strings"
  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. table := tablewriter.NewWriter(os.Stdout)
  17. table.SetHeader([]string{"Name", "Admin", "Networks", "Groups"})
  18. for _, d := range *functions.ListUsers() {
  19. table.Append([]string{d.UserName, strconv.FormatBool(d.IsAdmin), strings.Join(d.Networks, ", "), strings.Join(d.Groups, ", ")})
  20. }
  21. table.Render()
  22. },
  23. }
  24. func init() {
  25. rootCmd.AddCommand(userListCmd)
  26. }