-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathusers.go
More file actions
91 lines (81 loc) · 2.37 KB
/
users.go
File metadata and controls
91 lines (81 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package parser
import (
"github.com/drycc/workflow-cli/internal/commands"
"github.com/drycc/workflow-cli/internal/template"
"github.com/drycc/workflow-cli/pkg/i18n"
"github.com/spf13/cobra"
)
// NewUsersCommand creates the users command
func NewUsersCommand(cmdr *commands.DryccCmd) *cobra.Command {
cmd := &cobra.Command{
Use: "users",
Short: i18n.T("Manage registered users"),
RunE: func(_ *cobra.Command, _ []string) error {
results, _ := commands.ResponseLimit(limit)
return cmdr.UsersList(results)
},
}
cmd.Flags().IntVarP(&limit, "limit", "l", 0, i18n.T("The maximum number of results to display"))
cmd.AddCommand(usersListCommand(cmdr))
cmd.AddCommand(usersEnableCommand(cmdr))
cmd.AddCommand(usersDisableCommand(cmdr))
return cmd
}
func usersListCommand(cmdr *commands.DryccCmd) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: i18n.T("List all registered users"),
RunE: func(_ *cobra.Command, _ []string) error {
results, _ := commands.ResponseLimit(limit)
return cmdr.UsersList(results)
},
}
cmd.Flags().IntVarP(&limit, "limit", "l", 0, i18n.T("The maximum number of results to display"))
return cmd
}
func usersEnableCommand(cmdr *commands.DryccCmd) *cobra.Command {
var flags struct {
username string
}
cmd := &cobra.Command{
Use: "enable <username>",
Example: template.CustomExample(
"drycc users enable john_doe",
map[string]string{
"<username>": i18n.T("The username you want to enable"),
},
),
Short: i18n.T("Enable a user"),
Long: i18n.T(`Enable a user when his status is disabled.
Requires admin privileges.`),
Args: cobra.ExactArgs(1),
RunE: func(_ *cobra.Command, args []string) error {
flags.username = args[0]
return cmdr.UsersEnable(flags.username)
},
}
return cmd
}
func usersDisableCommand(cmdr *commands.DryccCmd) *cobra.Command {
var flags struct {
username string
}
cmd := &cobra.Command{
Use: "disable <username>",
Example: template.CustomExample(
"drycc users disable john_doe",
map[string]string{
"<username>": i18n.T("The username you want to disable"),
},
),
Short: i18n.T("Disable a user"),
Long: i18n.T(`Disable a user when his status is disabled.
Requires admin privileges.`),
Args: cobra.ExactArgs(1),
RunE: func(_ *cobra.Command, args []string) error {
flags.username = args[0]
return cmdr.UsersDisable(flags.username)
},
}
return cmd
}