package main import ( "fmt" "log" "strings" "syscall" "golang.org/x/term" ) func hiddenPrompt(prompt string) (string, error) { fmt.Print(prompt) bytes, err := term.ReadPassword(int(syscall.Stdin)) if err != nil { return "", err } fmt.Println() return strings.TrimSpace(string(bytes)), nil } var createUser = &Command{ Name: "user", Execute: func(args []string) { if len(args) < 1 { fmt.Println("error: no username provided") return; } username := args[0] var password string var err error if len(args) == 1 { password, err = hiddenPrompt("Enter password: ") if err != nil { log.Fatal(err) } confirm, err := hiddenPrompt("Confirm password: ") if err != nil { log.Fatal(err) } if password != confirm { fmt.Println("passwords do not match!") return } } else { password = args[1] } _, err = p.CreateUser(username, password) if err != nil { log.Fatal(err) } fmt.Printf("created user %v\n", username) }, } var createEndpoint = &Command{ Name: "endpoint", Execute: func(args []string) { if len(args) < 3 { fmt.Println("error: name, URI, and address must be specified!") return } name := args[0] path := args[1] addr := args[2] _, err := p.CreateEndpoint(name, path, addr) if err != nil { log.Fatal(err) } fmt.Printf("created endpoint %v\n", name) }, } func CreateInit(parser *Command) { create := &Command{ Name: "create", Branch: true, } create.AddCommand(createUser) create.AddCommand(createEndpoint) parser.AddCommand(create) }