From 1939949fcdd5d540fd20ead79b9c5d27e85e8f9d Mon Sep 17 00:00:00 2001 From: Sascha Date: Sun, 9 May 2021 11:14:45 +0200 Subject: CLI: Add non-interactive option to interactive commands (#651) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add option to skip the AvatarURL input request Using an empty string for the avatar cli flag e.g. `git-bug user create -a ""` will still result in a prompt. As the avatar URL is an optional option, it should be possible to skip asking for it entirely. Otherwise automated user creation via a script must make use of pipe hacks. * Add global --non-interactive cmdline option * Replace --skipAvatar for --non-interactive option * Cmd BugAdd: respect non-interactive option * Cmd bridge configure: respect non-interactive opt * Cmd CommentAdd: respect non-interactive option * Cmd CommentEdit: respect non-interactive option * Cmd TermUI: respect non-interactive option * Cmd TitleEdit: respect non-interactive option * Remove global non-interactive option * Cmd UserCreate: Use local non-interactive option * Cmd BugAdd: Use local non-interactive option * Cmd BridgeConfigure: Use local non-interactive option * Cmd CommentAdd: Use local non-interactive option * Cmd CommentEdit: Use local non-interactive option * Cmd TermUI: Drop non-interactive option It should be obviouse that the termui is an interactive command. * Cmd TitleEdit: Use local non-interactive option * Update docs * Bridge GitHub: respect non-interactive option * Bridge GitLab: respect non-interactive option * Bridge Jira: respect non-interactive and token opt * Fix failing compilation * Bridge launchpad: respect non-interactive option * bridge: isNonInteractive --> interactive Co-authored-by: Michael Muré --- commands/user_create.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'commands/user_create.go') diff --git a/commands/user_create.go b/commands/user_create.go index 06879f2e..0dcfa9b3 100644 --- a/commands/user_create.go +++ b/commands/user_create.go @@ -7,9 +7,10 @@ import ( ) type createUserOptions struct { - name string - email string - avatarURL string + name string + email string + avatarURL string + nonInteractive bool } func newUserCreateCommand() *cobra.Command { @@ -30,13 +31,14 @@ func newUserCreateCommand() *cobra.Command { flags.StringVarP(&options.name, "name", "n", "", "Name to identify the user") flags.StringVarP(&options.email, "email", "e", "", "Email of the user") flags.StringVarP(&options.avatarURL, "avatar", "a", "", "Avatar URL") + flags.BoolVar(&options.nonInteractive, "non-interactive", false, "Do not ask for user input") return cmd } func runUserCreate(env *Env, opts createUserOptions) error { - if opts.name == "" { + if !opts.nonInteractive && opts.name == "" { preName, err := env.backend.GetUserName() if err != nil { return err @@ -47,7 +49,7 @@ func runUserCreate(env *Env, opts createUserOptions) error { } } - if opts.email == "" { + if !opts.nonInteractive && opts.email == "" { preEmail, err := env.backend.GetUserEmail() if err != nil { return err @@ -59,7 +61,7 @@ func runUserCreate(env *Env, opts createUserOptions) error { } } - if opts.avatarURL == "" { + if !opts.nonInteractive && opts.avatarURL == "" { var err error opts.avatarURL, err = input.Prompt("Avatar URL", "avatar") if err != nil { -- cgit