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é --- bridge/github/config.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'bridge/github') diff --git a/bridge/github/config.go b/bridge/github/config.go index 55a09c53..9889f403 100644 --- a/bridge/github/config.go +++ b/bridge/github/config.go @@ -40,7 +40,7 @@ func (g *Github) ValidParams() map[string]interface{} { } } -func (g *Github) Configure(repo *cache.RepoCache, params core.BridgeParams) (core.Configuration, error) { +func (g *Github) Configure(repo *cache.RepoCache, params core.BridgeParams, interactive bool) (core.Configuration, error) { var err error var owner string var project string @@ -60,6 +60,9 @@ func (g *Github) Configure(repo *cache.RepoCache, params core.BridgeParams) (cor } default: // terminal prompt + if !interactive { + return nil, fmt.Errorf("Non-interactive-mode is active. Please specify the remote repository with --owner and --project, or via --url option.") + } owner, project, err = promptURL(repo) if err != nil { return nil, err @@ -99,6 +102,9 @@ func (g *Github) Configure(repo *cache.RepoCache, params core.BridgeParams) (cor cred = token default: if params.Login == "" { + if !interactive { + return nil, fmt.Errorf("Non-interactive-mode is active. Please specify a login via the --login option.") + } login, err = promptLogin() } else { // validate login and override with the correct case @@ -110,6 +116,10 @@ func (g *Github) Configure(repo *cache.RepoCache, params core.BridgeParams) (cor if err != nil { return nil, err } + + if !interactive { + return nil, fmt.Errorf("Non-interactive-mode is active. Please specify a access token via the --token option.") + } cred, err = promptTokenOptions(repo, login, owner, project) if err != nil { return nil, err -- cgit