Skip to content

Commit 38a4176

Browse files
committed
refactor(cli): user add command
1 parent c1e9e52 commit 38a4176

File tree

7 files changed

+23
-28
lines changed

7 files changed

+23
-28
lines changed

cli/cmd/migrate.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ func init() {
1212
var migrateCmd = &cobra.Command{
1313
Use: "migrate",
1414
Short: "Execute migrations",
15-
// Long: `All software has versions. This is Hugo's`,
16-
1715
Run: func(cmd *cobra.Command, args []string) {
1816
store := createStore()
1917
defer store.Close()

cli/cmd/root.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ var configPath string
2121
var rootCmd = &cobra.Command{
2222
Use: "semaphore",
2323
Short: "Ansible Semaphore is a beautiful web UI for Ansible",
24-
Long: `A Fast and Flexible Static Site Generator built with
25-
love by spf13 and friends in Go.
26-
Complete documentation is available at https://ansible-semaphore.com`,
24+
Long: `Ansible Semaphore is a beautiful web UI for Ansible.
25+
Source code is available at https://github.com/ansible-semaphore/semaphore.
26+
Complete documentation is available at https://ansible-semaphore.com.`,
2727
Run: func(cmd *cobra.Command, args []string) {
2828
if len(args) == 0 && configPath == "" {
2929
_ = cmd.Help()

cli/cmd/service.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ func init() {
1212

1313
var serviceCmd = &cobra.Command{
1414
Use: "service",
15-
Short: "Run Ansible Semaphore service",
16-
// Long: `All software has versions. This is Hugo's`,
17-
15+
Short: "Run Semaphore service",
1816
Run: func(cmd *cobra.Command, args []string) {
1917
runService()
2018
},

cli/cmd/setup.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ func init() {
1919
var setupCmd = &cobra.Command{
2020
Use: "setup",
2121
Short: "Perform interactive setup",
22-
// Long: `All software has versions. This is Hugo's`,
2322
Run: func(cmd *cobra.Command, args []string) {
2423
doSetup()
2524
},

cli/cmd/user.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,24 @@ import (
55
"os"
66
)
77

8-
type UserAddArgs struct {
9-
Username string
10-
Name string
11-
Email string
12-
Password string
8+
type userArgs struct {
9+
login string
10+
name string
11+
email string
12+
password string
1313
}
1414

15-
var UserAdd *UserAddArgs
16-
1715
func init() {
1816
rootCmd.AddCommand(userCmd)
1917
}
2018

2119
var userCmd = &cobra.Command{
2220
Use: "user",
2321
Short: "Manage users",
24-
// Long: `All software has versions. This is Hugo's`,
2522
Run: func(cmd *cobra.Command, args []string) {
2623
if len(args) == 0 {
2724
_ = cmd.Help()
2825
os.Exit(0)
2926
}
3027
},
31-
}
28+
}

cli/cmd/user_add.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,34 @@ import (
66
"github.com/spf13/cobra"
77
)
88

9+
var newUserArgs userArgs
10+
911
func init() {
12+
userAddCmd.PersistentFlags().StringVar(&newUserArgs.login, "login", "", "New user login")
13+
userAddCmd.PersistentFlags().StringVar(&newUserArgs.name, "name", "", "New user name")
14+
userAddCmd.PersistentFlags().StringVar(&newUserArgs.email, "email", "", "New user email")
15+
userAddCmd.PersistentFlags().StringVar(&newUserArgs.password, "password", "", "New user password")
1016
userCmd.AddCommand(userAddCmd)
1117
}
1218

1319
var userAddCmd = &cobra.Command{
1420
Use: "add",
15-
Short: "Print the version number of Semaphore",
16-
17-
// Long: `All software has versions. This is Hugo's`,
21+
Short: "Add new user",
1822
Run: func(cmd *cobra.Command, args []string) {
1923
store := createStore()
2024
defer store.Close()
2125

2226
if _, err := store.CreateUser(db.UserWithPwd{
23-
Pwd: UserAdd.Password,
27+
Pwd: newUserArgs.password,
2428
User: db.User{
25-
Name: UserAdd.Name,
26-
Username: UserAdd.Username,
27-
Email: UserAdd.Email,
29+
Name: newUserArgs.name,
30+
Username: newUserArgs.login,
31+
Email: newUserArgs.email,
2832
},
2933
}); err != nil {
3034
panic(err)
3135
}
3236

33-
fmt.Printf("User %s <%s> added!", UserAdd.Username, UserAdd.Email)
37+
fmt.Printf("User %s <%s> added!", newUserArgs.login, newUserArgs.email)
3438
},
3539
}

cli/cmd/version.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ func init() {
1212

1313
var versionCmd = &cobra.Command{
1414
Use: "version",
15-
Short: "Print the version number of Semaphore",
16-
// Long: `All software has versions. This is Hugo's`,
15+
Short: "Print the version of Semaphore",
1716
Run: func(cmd *cobra.Command, args []string) {
1817
fmt.Println(util.Version)
1918
},

0 commit comments

Comments
 (0)