Skip to content

Commit

Permalink
add yes flag
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoshiro.maruo committed Apr 9, 2022
1 parent 4e87c63 commit c0db31a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ rdiam add -u user1@email.com,user2@email.com -g group1,group2`,

cmd.Flags().StringSliceP("users", "u", []string{}, "Specify user email(s)")
cmd.Flags().StringSliceP("groups", "g", []string{}, "Specify group(s)")
cmd.Flags().BoolP("yes", "y", false, "Automatic yes to prompts")

if err := cmd.MarkFlagRequired("users"); err != nil {
panic(err)
Expand All @@ -51,16 +52,23 @@ func runAddCmd(cmd *cobra.Command, _ []string) error {
return xerrors.Errorf("failed to parse groups flag: %+w", err)
}

yes, err := cmd.Flags().GetBool("yes")
if err != nil {
return xerrors.Errorf("failed to parse yes flag: %+w", err)
}

fmt.Printf("users: %s\n", users)
fmt.Printf("groups: %s\n", groups)
fmt.Printf("Are you sure? [y/n]")

reader := bufio.NewReader(os.Stdin)
res, err := reader.ReadString('\n')
if !yes {
fmt.Printf("Are you sure? [y/n]")
reader := bufio.NewReader(os.Stdin)
res, err := reader.ReadString('\n')

if err != nil || strings.TrimSpace(res) != "y" {
fmt.Println("Abort.")
return nil
if err != nil || strings.TrimSpace(res) != "y" {
fmt.Println("Abort.")
return nil
}
}

return impl.AddCmd(globalClient, users, groups)
Expand Down

0 comments on commit c0db31a

Please sign in to comment.