#10042: Add error messages for 'gh gist view/edit' prompts when no TTY is detected
This commit is contained in:
parent
a3a283ca83
commit
f4f8840c3f
3 changed files with 13 additions and 13 deletions
|
|
@ -108,6 +108,9 @@ func editRun(opts *EditOptions) error {
|
|||
if gistID == "" {
|
||||
cs := opts.IO.ColorScheme()
|
||||
if gistID == "" {
|
||||
if !opts.IO.CanPrompt() {
|
||||
return cmdutil.FlagErrorf("gist ID or URL required when not running interactively")
|
||||
}
|
||||
gistID, err = shared.PromptGists(opts.Prompter, client, host, cs)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Comman
|
|||
}
|
||||
|
||||
if !opts.IO.IsStdoutTTY() {
|
||||
return cmdutil.FlagErrorf("run or gist ID required when not running interactively\n\nUsage: gh gist view [<id> | <url>] [flags]\n\nFlags:\n -f, --filename string Display a single file from the gist\n --files List file names from the gist\n -r, --raw Print raw instead of rendered gist contents\n -w, --web Open gist in the browser\n")
|
||||
opts.Raw = true
|
||||
}
|
||||
|
||||
if runF != nil {
|
||||
|
|
@ -89,6 +89,10 @@ func viewRun(opts *ViewOptions) error {
|
|||
|
||||
cs := opts.IO.ColorScheme()
|
||||
if gistID == "" {
|
||||
if !opts.IO.CanPrompt() {
|
||||
return cmdutil.FlagErrorf("gist ID or URL required when not running interactively")
|
||||
}
|
||||
|
||||
gistID, err = shared.PromptGists(opts.Prompter, client, hostname, cs)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -20,11 +20,10 @@ import (
|
|||
|
||||
func TestNewCmdView(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
cli string
|
||||
wants ViewOptions
|
||||
tty bool
|
||||
wantsErr bool
|
||||
name string
|
||||
cli string
|
||||
wants ViewOptions
|
||||
tty bool
|
||||
}{
|
||||
{
|
||||
name: "tty no arguments",
|
||||
|
|
@ -45,7 +44,6 @@ func TestNewCmdView(t *testing.T) {
|
|||
Selector: "123",
|
||||
ListFiles: false,
|
||||
},
|
||||
wantsErr: true,
|
||||
},
|
||||
{
|
||||
name: "filename passed",
|
||||
|
|
@ -98,11 +96,6 @@ func TestNewCmdView(t *testing.T) {
|
|||
return nil
|
||||
})
|
||||
|
||||
_, err = cmd.ExecuteC()
|
||||
if tt.wantsErr {
|
||||
assert.Error(t, err)
|
||||
return
|
||||
}
|
||||
cmd.SetArgs(argv)
|
||||
cmd.SetIn(&bytes.Buffer{})
|
||||
cmd.SetOut(&bytes.Buffer{})
|
||||
|
|
@ -166,7 +159,7 @@ func Test_viewRun(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
wantOut: "test interactive mode\n",
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "filename selected",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue