File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -13,4 +13,5 @@ var CmdUser = &cobra.Command{
1313
1414func init () {
1515 CmdUser .AddCommand (cmdUserAdd )
16+ CmdUser .AddCommand (cmdUserDel )
1617}
You can’t perform that action at this time.
0 commit comments