Merge pull request #5671 from cli/pr-create-nontty
pr create: ensure clear error when body is missing in nonTTY mode
This commit is contained in:
commit
e837b7bc4d
3 changed files with 32 additions and 5 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue