diff --git a/pkg/cmd/issue/create/create.go b/pkg/cmd/issue/create/create.go index 51f828f8d..64d1b3cf2 100644 --- a/pkg/cmd/issue/create/create.go +++ b/pkg/cmd/issue/create/create.go @@ -89,7 +89,7 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co opts.Interactive = !(titleProvided && bodyProvided) if opts.Interactive && !opts.IO.CanPrompt() { - return cmdutil.FlagErrorf("must provide title and body when not running interactively") + return cmdutil.FlagErrorf("must provide `--title` and `--body` when not running interactively") } if runF != nil { diff --git a/pkg/cmd/pr/create/create.go b/pkg/cmd/pr/create/create.go index f0b4c7f94..1c65046d5 100644 --- a/pkg/cmd/pr/create/create.go +++ b/pkg/cmd/pr/create/create.go @@ -130,10 +130,6 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co return cmdutil.FlagErrorf("`--recover` only supported when running interactively") } - if !opts.IO.CanPrompt() && !opts.WebMode && !opts.TitleProvided && !opts.Autofill { - return cmdutil.FlagErrorf("`--title` or `--fill` required when not running interactively") - } - if opts.IsDraft && opts.WebMode { return errors.New("the `--draft` flag is not supported with `--web`") } @@ -154,6 +150,10 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co opts.BodyProvided = true } + if !opts.IO.CanPrompt() && !opts.WebMode && !opts.Autofill && (!opts.TitleProvided || !opts.BodyProvided) { + return cmdutil.FlagErrorf("must provide `--title` and `--body` (or `--fill`) when not running interactively") + } + if runF != nil { return runF(opts) } diff --git a/pkg/cmd/pr/create/create_test.go b/pkg/cmd/pr/create/create_test.go index 5ba641eed..9f7d8ce44 100644 --- a/pkg/cmd/pr/create/create_test.go +++ b/pkg/cmd/pr/create/create_test.go @@ -48,6 +48,31 @@ func TestNewCmdCreate(t *testing.T) { cli: "", wantsErr: true, }, + { + name: "only title non-tty", + tty: false, + cli: "--title mytitle", + wantsErr: true, + }, + { + name: "minimum non-tty", + tty: false, + cli: "--title mytitle --body ''", + wantsErr: false, + wantsOpts: CreateOptions{ + Title: "mytitle", + TitleProvided: true, + Body: "", + BodyProvided: true, + Autofill: false, + RecoverFile: "", + WebMode: false, + IsDraft: false, + BaseBranch: "", + HeadBranch: "", + MaintainerCanModify: true, + }, + }, { name: "empty tty", tty: true, @@ -130,6 +155,8 @@ func TestNewCmdCreate(t *testing.T) { args, err := shlex.Split(tt.cli) require.NoError(t, err) cmd.SetArgs(args) + cmd.SetOut(stdout) + cmd.SetErr(stderr) _, err = cmd.ExecuteC() if tt.wantsErr { assert.Error(t, err)