Skip to content

Commit 7e99d3c

Browse files
committed
feat:add cmd delete user
1 parent e2ff035 commit 7e99d3c

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

cmd/user/del.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package user
2+
3+
import (
4+
"bytes"
5+
"encoding/json"
6+
"fmt"
7+
"grm/common"
8+
"grm/global"
9+
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var delusername string
14+
15+
var cmdUserDel = &cobra.Command{
16+
Use: "delete",
17+
Short: "delete user",
18+
Run: userDelFunc,
19+
}
20+
21+
func userDelFunc(cmd *cobra.Command, args []string) {
22+
23+
fmt.Println("Please input username:")
24+
fmt.Scan(&delusername)
25+
26+
user := global.GlobalConf.Accounts
27+
delete(user, delusername)
28+
29+
global.GlobalConf.Accounts = user
30+
31+
buffer := &bytes.Buffer{}
32+
encoder := json.NewEncoder(buffer)
33+
err := encoder.Encode(global.GlobalConf)
34+
if err != nil {
35+
fmt.Println(err)
36+
}
37+
common.WriteData(buffer.Bytes())
38+
39+
fmt.Println("delete success!")
40+
}

cmd/user/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ var CmdUser = &cobra.Command{
1313

1414
func init() {
1515
CmdUser.AddCommand(cmdUserAdd)
16+
CmdUser.AddCommand(cmdUserDel)
1617
}

0 commit comments

Comments
 (0)