github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/kbfs/kbpagesconfig/cmd_user.go (about) 1 // Copyright 2018 Keybase Inc. All rights reserved. 2 // Use of this source code is governed by a BSD 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "fmt" 9 "os" 10 11 "github.com/urfave/cli" 12 ) 13 14 var userAddCmd = cli.Command{ 15 Name: "add", 16 Usage: "add new user(s) to config", 17 UsageText: "add <username> [username ...]", 18 Action: func(c *cli.Context) { 19 if len(c.Args()) < 1 { 20 fmt.Fprintln(os.Stderr, "empty username") 21 os.Exit(1) 22 } 23 editor, err := newKBPConfigEditor(c.GlobalString("dir")) 24 if err != nil { 25 fmt.Fprintf(os.Stderr, 26 "creating config editor error: %v\n", err) 27 os.Exit(1) 28 } 29 for _, username := range c.Args() { 30 if err := editor.setUser(username, true); err != nil { 31 fmt.Fprintf(os.Stderr, 32 "adding user (%s) error: %v\n", username, err) 33 os.Exit(1) 34 } 35 } 36 if err := editor.confirmAndWrite(); err != nil { 37 fmt.Fprintf(os.Stderr, "writing new config error: %v\n", err) 38 os.Exit(1) 39 } 40 }, 41 } 42 43 var userChangeCmd = cli.Command{ 44 Name: "change", 45 Usage: "change password(s) for user(s) in the config", 46 UsageText: "change <username> [username ...]", 47 Action: func(c *cli.Context) { 48 if len(c.Args()) < 1 { 49 fmt.Fprintln(os.Stderr, "empty username") 50 os.Exit(1) 51 } 52 editor, err := newKBPConfigEditor(c.GlobalString("dir")) 53 if err != nil { 54 fmt.Fprintf(os.Stderr, 55 "creating config editor error: %v\n", err) 56 os.Exit(1) 57 } 58 for _, username := range c.Args() { 59 if err := editor.setUser(username, false); err != nil { 60 fmt.Fprintf(os.Stderr, 61 "change user (%s) password error: %v\n", username, err) 62 os.Exit(1) 63 } 64 } 65 if err := editor.confirmAndWrite(); err != nil { 66 fmt.Fprintf(os.Stderr, "writing new config error: %v\n", err) 67 os.Exit(1) 68 } 69 }, 70 } 71 72 var userRemoveCmd = cli.Command{ 73 Name: "remove", 74 Usage: "remove user(s) from config", 75 UsageText: "remove <username> [username ...]", 76 Action: func(c *cli.Context) { 77 if len(c.Args()) < 1 { 78 fmt.Fprintln(os.Stderr, "empty username") 79 os.Exit(1) 80 } 81 editor, err := newKBPConfigEditor(c.GlobalString("dir")) 82 if err != nil { 83 fmt.Fprintf(os.Stderr, 84 "creating config editor error: %v\n", err) 85 os.Exit(1) 86 } 87 for _, username := range c.Args() { 88 editor.removeUser(username) 89 } 90 if err := editor.confirmAndWrite(); err != nil { 91 fmt.Fprintf(os.Stderr, "writing new config error: %v\n", err) 92 os.Exit(1) 93 } 94 }, 95 } 96 97 var userCmd = cli.Command{ 98 Name: "user", 99 Usage: "make changes to 'users' section of the config", 100 UsageText: "user <add|remove> <args>", 101 Subcommands: []cli.Command{ 102 userAddCmd, 103 userChangeCmd, 104 userRemoveCmd, 105 }, 106 }