move prompter to own package
This commit is contained in:
parent
40ecb8c188
commit
f7d5c5f725
14 changed files with 55 additions and 49 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
package cmdutil
|
package prompter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
@ -10,6 +10,18 @@ import (
|
||||||
"github.com/cli/cli/v2/pkg/surveyext"
|
"github.com/cli/cli/v2/pkg/surveyext"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:generate moq -rm -out prompter_mock.go . Prompter
|
||||||
|
type Prompter interface {
|
||||||
|
Select(string, string, []string) (int, error)
|
||||||
|
MultiSelect(string, string, []string) (int, error)
|
||||||
|
Input(string, string) (string, error)
|
||||||
|
InputHostname() (string, error)
|
||||||
|
Password(string) (string, error)
|
||||||
|
AuthToken() (string, error)
|
||||||
|
Confirm(string, bool) (bool, error)
|
||||||
|
MarkdownEditor(string, string, bool) (string, error)
|
||||||
|
}
|
||||||
|
|
||||||
func NewPrompter(editorCmd string, stdin io.Reader, stdout, stderr io.Writer) Prompter {
|
func NewPrompter(editorCmd string, stdin io.Reader, stdout, stderr io.Writer) Prompter {
|
||||||
return &surveyPrompter{
|
return &surveyPrompter{
|
||||||
editorCmd: editorCmd,
|
editorCmd: editorCmd,
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// Code generated by moq; DO NOT EDIT.
|
// Code generated by moq; DO NOT EDIT.
|
||||||
// github.com/matryer/moq
|
// github.com/matryer/moq
|
||||||
|
|
||||||
package cmdutil
|
package prompter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/MakeNowJust/heredoc"
|
"github.com/MakeNowJust/heredoc"
|
||||||
"github.com/cli/cli/v2/internal/config"
|
"github.com/cli/cli/v2/internal/config"
|
||||||
"github.com/cli/cli/v2/internal/ghinstance"
|
"github.com/cli/cli/v2/internal/ghinstance"
|
||||||
|
"github.com/cli/cli/v2/internal/prompter"
|
||||||
"github.com/cli/cli/v2/pkg/cmd/auth/shared"
|
"github.com/cli/cli/v2/pkg/cmd/auth/shared"
|
||||||
"github.com/cli/cli/v2/pkg/cmdutil"
|
"github.com/cli/cli/v2/pkg/cmdutil"
|
||||||
"github.com/cli/cli/v2/pkg/iostreams"
|
"github.com/cli/cli/v2/pkg/iostreams"
|
||||||
|
|
@ -19,7 +20,7 @@ type LoginOptions struct {
|
||||||
IO *iostreams.IOStreams
|
IO *iostreams.IOStreams
|
||||||
Config func() (config.Config, error)
|
Config func() (config.Config, error)
|
||||||
HttpClient func() (*http.Client, error)
|
HttpClient func() (*http.Client, error)
|
||||||
Prompter cmdutil.Prompter
|
Prompter prompter.Prompter
|
||||||
|
|
||||||
MainExecutable string
|
MainExecutable string
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import (
|
||||||
|
|
||||||
"github.com/MakeNowJust/heredoc"
|
"github.com/MakeNowJust/heredoc"
|
||||||
"github.com/cli/cli/v2/internal/config"
|
"github.com/cli/cli/v2/internal/config"
|
||||||
|
"github.com/cli/cli/v2/internal/prompter"
|
||||||
"github.com/cli/cli/v2/internal/run"
|
"github.com/cli/cli/v2/internal/run"
|
||||||
"github.com/cli/cli/v2/pkg/cmdutil"
|
"github.com/cli/cli/v2/pkg/cmdutil"
|
||||||
"github.com/cli/cli/v2/pkg/httpmock"
|
"github.com/cli/cli/v2/pkg/httpmock"
|
||||||
|
|
@ -364,7 +365,7 @@ func Test_loginRun_Survey(t *testing.T) {
|
||||||
name string
|
name string
|
||||||
opts *LoginOptions
|
opts *LoginOptions
|
||||||
httpStubs func(*httpmock.Registry)
|
httpStubs func(*httpmock.Registry)
|
||||||
prompterStubs func(*cmdutil.PrompterMock)
|
prompterStubs func(*prompter.PrompterMock)
|
||||||
runStubs func(*run.CommandStubber)
|
runStubs func(*run.CommandStubber)
|
||||||
wantHosts string
|
wantHosts string
|
||||||
wantErrOut *regexp.Regexp
|
wantErrOut *regexp.Regexp
|
||||||
|
|
@ -383,7 +384,7 @@ func Test_loginRun_Survey(t *testing.T) {
|
||||||
httpStubs: func(reg *httpmock.Registry) {
|
httpStubs: func(reg *httpmock.Registry) {
|
||||||
reg.Register(httpmock.REST("GET", ""), httpmock.ScopesResponder("repo,read:org"))
|
reg.Register(httpmock.REST("GET", ""), httpmock.ScopesResponder("repo,read:org"))
|
||||||
},
|
},
|
||||||
prompterStubs: func(pm *cmdutil.PrompterMock) {
|
prompterStubs: func(pm *prompter.PrompterMock) {
|
||||||
pm.SelectFunc = func(_, _ string, _ []string) (int, error) {
|
pm.SelectFunc = func(_, _ string, _ []string) (int, error) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
@ -403,7 +404,7 @@ func Test_loginRun_Survey(t *testing.T) {
|
||||||
user: jillv
|
user: jillv
|
||||||
git_protocol: https
|
git_protocol: https
|
||||||
`),
|
`),
|
||||||
prompterStubs: func(pm *cmdutil.PrompterMock) {
|
prompterStubs: func(pm *prompter.PrompterMock) {
|
||||||
pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) {
|
pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) {
|
||||||
switch prompt {
|
switch prompt {
|
||||||
case "What is your preferred protocol for Git operations?":
|
case "What is your preferred protocol for Git operations?":
|
||||||
|
|
@ -437,7 +438,7 @@ func Test_loginRun_Survey(t *testing.T) {
|
||||||
opts: &LoginOptions{
|
opts: &LoginOptions{
|
||||||
Interactive: true,
|
Interactive: true,
|
||||||
},
|
},
|
||||||
prompterStubs: func(pm *cmdutil.PrompterMock) {
|
prompterStubs: func(pm *prompter.PrompterMock) {
|
||||||
pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) {
|
pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) {
|
||||||
switch prompt {
|
switch prompt {
|
||||||
case "What account do you want to log into?":
|
case "What account do you want to log into?":
|
||||||
|
|
@ -476,7 +477,7 @@ func Test_loginRun_Survey(t *testing.T) {
|
||||||
opts: &LoginOptions{
|
opts: &LoginOptions{
|
||||||
Interactive: true,
|
Interactive: true,
|
||||||
},
|
},
|
||||||
prompterStubs: func(pm *cmdutil.PrompterMock) {
|
prompterStubs: func(pm *prompter.PrompterMock) {
|
||||||
pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) {
|
pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) {
|
||||||
switch prompt {
|
switch prompt {
|
||||||
case "What account do you want to log into?":
|
case "What account do you want to log into?":
|
||||||
|
|
@ -506,7 +507,7 @@ func Test_loginRun_Survey(t *testing.T) {
|
||||||
opts: &LoginOptions{
|
opts: &LoginOptions{
|
||||||
Interactive: true,
|
Interactive: true,
|
||||||
},
|
},
|
||||||
prompterStubs: func(pm *cmdutil.PrompterMock) {
|
prompterStubs: func(pm *prompter.PrompterMock) {
|
||||||
pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) {
|
pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) {
|
||||||
switch prompt {
|
switch prompt {
|
||||||
case "What account do you want to log into?":
|
case "What account do you want to log into?":
|
||||||
|
|
@ -560,7 +561,7 @@ func Test_loginRun_Survey(t *testing.T) {
|
||||||
httpmock.StringResponse(`{"data":{"viewer":{"login":"jillv"}}}`))
|
httpmock.StringResponse(`{"data":{"viewer":{"login":"jillv"}}}`))
|
||||||
}
|
}
|
||||||
|
|
||||||
pm := &cmdutil.PrompterMock{}
|
pm := &prompter.PrompterMock{}
|
||||||
pm.ConfirmFunc = func(_ string, _ bool) (bool, error) {
|
pm.ConfirmFunc = func(_ string, _ bool) (bool, error) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,14 @@ import (
|
||||||
"github.com/MakeNowJust/heredoc"
|
"github.com/MakeNowJust/heredoc"
|
||||||
"github.com/cli/cli/v2/git"
|
"github.com/cli/cli/v2/git"
|
||||||
"github.com/cli/cli/v2/internal/ghinstance"
|
"github.com/cli/cli/v2/internal/ghinstance"
|
||||||
|
"github.com/cli/cli/v2/internal/prompter"
|
||||||
"github.com/cli/cli/v2/internal/run"
|
"github.com/cli/cli/v2/internal/run"
|
||||||
"github.com/cli/cli/v2/pkg/cmdutil"
|
|
||||||
"github.com/google/shlex"
|
"github.com/google/shlex"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GitCredentialFlow struct {
|
type GitCredentialFlow struct {
|
||||||
Executable string
|
Executable string
|
||||||
Prompter cmdutil.Prompter
|
Prompter prompter.Prompter
|
||||||
|
|
||||||
shouldSetup bool
|
shouldSetup bool
|
||||||
helper string
|
helper string
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ import (
|
||||||
"github.com/cli/cli/v2/api"
|
"github.com/cli/cli/v2/api"
|
||||||
"github.com/cli/cli/v2/internal/authflow"
|
"github.com/cli/cli/v2/internal/authflow"
|
||||||
"github.com/cli/cli/v2/internal/ghinstance"
|
"github.com/cli/cli/v2/internal/ghinstance"
|
||||||
|
"github.com/cli/cli/v2/internal/prompter"
|
||||||
"github.com/cli/cli/v2/pkg/cmd/ssh-key/add"
|
"github.com/cli/cli/v2/pkg/cmd/ssh-key/add"
|
||||||
"github.com/cli/cli/v2/pkg/cmdutil"
|
|
||||||
"github.com/cli/cli/v2/pkg/iostreams"
|
"github.com/cli/cli/v2/pkg/iostreams"
|
||||||
"github.com/cli/cli/v2/pkg/ssh"
|
"github.com/cli/cli/v2/pkg/ssh"
|
||||||
)
|
)
|
||||||
|
|
@ -34,7 +34,7 @@ type LoginOptions struct {
|
||||||
Scopes []string
|
Scopes []string
|
||||||
Executable string
|
Executable string
|
||||||
GitProtocol string
|
GitProtocol string
|
||||||
Prompter cmdutil.Prompter
|
Prompter prompter.Prompter
|
||||||
|
|
||||||
sshContext ssh.Context
|
sshContext ssh.Context
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/MakeNowJust/heredoc"
|
"github.com/MakeNowJust/heredoc"
|
||||||
|
"github.com/cli/cli/v2/internal/prompter"
|
||||||
"github.com/cli/cli/v2/internal/run"
|
"github.com/cli/cli/v2/internal/run"
|
||||||
"github.com/cli/cli/v2/pkg/cmdutil"
|
|
||||||
"github.com/cli/cli/v2/pkg/httpmock"
|
"github.com/cli/cli/v2/pkg/httpmock"
|
||||||
"github.com/cli/cli/v2/pkg/iostreams"
|
"github.com/cli/cli/v2/pkg/iostreams"
|
||||||
"github.com/cli/cli/v2/pkg/ssh"
|
"github.com/cli/cli/v2/pkg/ssh"
|
||||||
|
|
@ -47,7 +47,7 @@ func TestLogin_ssh(t *testing.T) {
|
||||||
httpmock.REST("POST", "api/v3/user/keys"),
|
httpmock.REST("POST", "api/v3/user/keys"),
|
||||||
httpmock.StringResponse(`{}`))
|
httpmock.StringResponse(`{}`))
|
||||||
|
|
||||||
pm := &cmdutil.PrompterMock{}
|
pm := &prompter.PrompterMock{}
|
||||||
pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) {
|
pm.SelectFunc = func(prompt, _ string, _ []string) (int, error) {
|
||||||
switch prompt {
|
switch prompt {
|
||||||
case "What is your preferred protocol for Git operations?":
|
case "What is your preferred protocol for Git operations?":
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"github.com/MakeNowJust/heredoc"
|
"github.com/MakeNowJust/heredoc"
|
||||||
"github.com/cli/cli/v2/internal/config"
|
"github.com/cli/cli/v2/internal/config"
|
||||||
"github.com/cli/cli/v2/internal/ghrepo"
|
"github.com/cli/cli/v2/internal/ghrepo"
|
||||||
|
"github.com/cli/cli/v2/internal/prompter"
|
||||||
"github.com/cli/cli/v2/pkg/cmdutil"
|
"github.com/cli/cli/v2/pkg/cmdutil"
|
||||||
"github.com/cli/cli/v2/pkg/extensions"
|
"github.com/cli/cli/v2/pkg/extensions"
|
||||||
"github.com/cli/cli/v2/pkg/httpmock"
|
"github.com/cli/cli/v2/pkg/httpmock"
|
||||||
|
|
@ -30,7 +31,7 @@ func TestNewCmdExtension(t *testing.T) {
|
||||||
name string
|
name string
|
||||||
args []string
|
args []string
|
||||||
managerStubs func(em *extensions.ExtensionManagerMock) func(*testing.T)
|
managerStubs func(em *extensions.ExtensionManagerMock) func(*testing.T)
|
||||||
prompterStubs func(pm *cmdutil.PrompterMock)
|
prompterStubs func(pm *prompter.PrompterMock)
|
||||||
isTTY bool
|
isTTY bool
|
||||||
wantErr bool
|
wantErr bool
|
||||||
errMsg string
|
errMsg string
|
||||||
|
|
@ -386,7 +387,7 @@ func TestNewCmdExtension(t *testing.T) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
isTTY: true,
|
isTTY: true,
|
||||||
prompterStubs: func(pm *cmdutil.PrompterMock) {
|
prompterStubs: func(pm *prompter.PrompterMock) {
|
||||||
pm.InputFunc = func(prompt, defVal string) (string, error) {
|
pm.InputFunc = func(prompt, defVal string) (string, error) {
|
||||||
if prompt == "Extension name:" {
|
if prompt == "Extension name:" {
|
||||||
return "test", nil
|
return "test", nil
|
||||||
|
|
@ -566,7 +567,7 @@ func TestNewCmdExtension(t *testing.T) {
|
||||||
assertFunc = tt.managerStubs(em)
|
assertFunc = tt.managerStubs(em)
|
||||||
}
|
}
|
||||||
|
|
||||||
pm := &cmdutil.PrompterMock{}
|
pm := &prompter.PrompterMock{}
|
||||||
if tt.prompterStubs != nil {
|
if tt.prompterStubs != nil {
|
||||||
tt.prompterStubs(pm)
|
tt.prompterStubs(pm)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"github.com/cli/cli/v2/git"
|
"github.com/cli/cli/v2/git"
|
||||||
"github.com/cli/cli/v2/internal/config"
|
"github.com/cli/cli/v2/internal/config"
|
||||||
"github.com/cli/cli/v2/internal/ghrepo"
|
"github.com/cli/cli/v2/internal/ghrepo"
|
||||||
|
"github.com/cli/cli/v2/internal/prompter"
|
||||||
"github.com/cli/cli/v2/pkg/cmd/extension"
|
"github.com/cli/cli/v2/pkg/cmd/extension"
|
||||||
"github.com/cli/cli/v2/pkg/cmdutil"
|
"github.com/cli/cli/v2/pkg/cmdutil"
|
||||||
"github.com/cli/cli/v2/pkg/iostreams"
|
"github.com/cli/cli/v2/pkg/iostreams"
|
||||||
|
|
@ -31,7 +32,7 @@ func New(appVersion string) *cmdutil.Factory {
|
||||||
f.HttpClient = httpClientFunc(f, appVersion) // Depends on Config, IOStreams, and appVersion
|
f.HttpClient = httpClientFunc(f, appVersion) // Depends on Config, IOStreams, and appVersion
|
||||||
f.Remotes = remotesFunc(f) // Depends on Config
|
f.Remotes = remotesFunc(f) // Depends on Config
|
||||||
f.BaseRepo = BaseRepoFunc(f) // Depends on Remotes
|
f.BaseRepo = BaseRepoFunc(f) // Depends on Remotes
|
||||||
f.Prompter = prompter(f) // Depends on Config and IOStreams
|
f.Prompter = newPrompter(f) // Depends on Config and IOStreams
|
||||||
f.Browser = browser(f) // Depends on Config, and IOStreams
|
f.Browser = browser(f) // Depends on Config, and IOStreams
|
||||||
f.ExtensionManager = extensionManager(f) // Depends on Config, HttpClient, and IOStreams
|
f.ExtensionManager = extensionManager(f) // Depends on Config, HttpClient, and IOStreams
|
||||||
|
|
||||||
|
|
@ -108,10 +109,10 @@ func browser(f *cmdutil.Factory) cmdutil.Browser {
|
||||||
return cmdutil.NewBrowser(browserLauncher(f), io.Out, io.ErrOut)
|
return cmdutil.NewBrowser(browserLauncher(f), io.Out, io.ErrOut)
|
||||||
}
|
}
|
||||||
|
|
||||||
func prompter(f *cmdutil.Factory) cmdutil.Prompter {
|
func newPrompter(f *cmdutil.Factory) prompter.Prompter {
|
||||||
editor, _ := cmdutil.DetermineEditor(f.Config)
|
editor, _ := cmdutil.DetermineEditor(f.Config)
|
||||||
io := f.IOStreams
|
io := f.IOStreams
|
||||||
return cmdutil.NewPrompter(editor, io.In, io.Out, io.ErrOut)
|
return prompter.NewPrompter(editor, io.In, io.Out, io.ErrOut)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Browser precedence
|
// Browser precedence
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/MakeNowJust/heredoc"
|
"github.com/MakeNowJust/heredoc"
|
||||||
"github.com/cli/cli/v2/api"
|
"github.com/cli/cli/v2/api"
|
||||||
"github.com/cli/cli/v2/internal/config"
|
"github.com/cli/cli/v2/internal/config"
|
||||||
|
"github.com/cli/cli/v2/internal/prompter"
|
||||||
"github.com/cli/cli/v2/pkg/cmd/pr/shared"
|
"github.com/cli/cli/v2/pkg/cmd/pr/shared"
|
||||||
"github.com/cli/cli/v2/pkg/cmdutil"
|
"github.com/cli/cli/v2/pkg/cmdutil"
|
||||||
"github.com/cli/cli/v2/pkg/iostreams"
|
"github.com/cli/cli/v2/pkg/iostreams"
|
||||||
|
|
@ -19,7 +20,7 @@ type ReviewOptions struct {
|
||||||
HttpClient func() (*http.Client, error)
|
HttpClient func() (*http.Client, error)
|
||||||
Config func() (config.Config, error)
|
Config func() (config.Config, error)
|
||||||
IO *iostreams.IOStreams
|
IO *iostreams.IOStreams
|
||||||
Prompter cmdutil.Prompter
|
Prompter prompter.Prompter
|
||||||
|
|
||||||
Finder shared.PRFinder
|
Finder shared.PRFinder
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/cli/cli/v2/context"
|
"github.com/cli/cli/v2/context"
|
||||||
"github.com/cli/cli/v2/internal/config"
|
"github.com/cli/cli/v2/internal/config"
|
||||||
"github.com/cli/cli/v2/internal/ghrepo"
|
"github.com/cli/cli/v2/internal/ghrepo"
|
||||||
|
"github.com/cli/cli/v2/internal/prompter"
|
||||||
"github.com/cli/cli/v2/pkg/cmd/pr/shared"
|
"github.com/cli/cli/v2/pkg/cmd/pr/shared"
|
||||||
"github.com/cli/cli/v2/pkg/cmdutil"
|
"github.com/cli/cli/v2/pkg/cmdutil"
|
||||||
"github.com/cli/cli/v2/pkg/httpmock"
|
"github.com/cli/cli/v2/pkg/httpmock"
|
||||||
|
|
@ -165,7 +166,7 @@ func Test_NewCmdReview(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func runCommand(rt http.RoundTripper, prompter cmdutil.Prompter, remotes context.Remotes, isTTY bool, cli string) (*test.CmdOut, error) {
|
func runCommand(rt http.RoundTripper, prompter prompter.Prompter, remotes context.Remotes, isTTY bool, cli string) (*test.CmdOut, error) {
|
||||||
ios, _, stdout, stderr := iostreams.Test()
|
ios, _, stdout, stderr := iostreams.Test()
|
||||||
ios.SetStdoutTTY(isTTY)
|
ios.SetStdoutTTY(isTTY)
|
||||||
ios.SetStdinTTY(isTTY)
|
ios.SetStdinTTY(isTTY)
|
||||||
|
|
@ -271,7 +272,7 @@ func TestPRReview_interactive(t *testing.T) {
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
pm := &cmdutil.PrompterMock{
|
pm := &prompter.PrompterMock{
|
||||||
SelectFunc: func(_, _ string, _ []string) (int, error) { return 1, nil },
|
SelectFunc: func(_, _ string, _ []string) (int, error) { return 1, nil },
|
||||||
MarkdownEditorFunc: func(_, _ string, _ bool) (string, error) { return "cool story", nil },
|
MarkdownEditorFunc: func(_, _ string, _ bool) (string, error) { return "cool story", nil },
|
||||||
ConfirmFunc: func(_ string, _ bool) (bool, error) { return true, nil },
|
ConfirmFunc: func(_ string, _ bool) (bool, error) { return true, nil },
|
||||||
|
|
@ -294,7 +295,7 @@ func TestPRReview_interactive_no_body(t *testing.T) {
|
||||||
|
|
||||||
shared.RunCommandFinder("", &api.PullRequest{ID: "THE-ID", Number: 123}, ghrepo.New("OWNER", "REPO"))
|
shared.RunCommandFinder("", &api.PullRequest{ID: "THE-ID", Number: 123}, ghrepo.New("OWNER", "REPO"))
|
||||||
|
|
||||||
pm := &cmdutil.PrompterMock{
|
pm := &prompter.PrompterMock{
|
||||||
SelectFunc: func(_, _ string, _ []string) (int, error) { return 2, nil },
|
SelectFunc: func(_, _ string, _ []string) (int, error) { return 2, nil },
|
||||||
MarkdownEditorFunc: func(_, _ string, _ bool) (string, error) { return "", nil },
|
MarkdownEditorFunc: func(_, _ string, _ bool) (string, error) { return "", nil },
|
||||||
}
|
}
|
||||||
|
|
@ -318,7 +319,7 @@ func TestPRReview_interactive_blank_approve(t *testing.T) {
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
pm := &cmdutil.PrompterMock{
|
pm := &prompter.PrompterMock{
|
||||||
SelectFunc: func(_, _ string, _ []string) (int, error) { return 1, nil },
|
SelectFunc: func(_, _ string, _ []string) (int, error) { return 1, nil },
|
||||||
MarkdownEditorFunc: func(_, defVal string, _ bool) (string, error) { return defVal, nil },
|
MarkdownEditorFunc: func(_, defVal string, _ bool) (string, error) { return defVal, nil },
|
||||||
ConfirmFunc: func(_ string, _ bool) (bool, error) { return true, nil },
|
ConfirmFunc: func(_ string, _ bool) (bool, error) { return true, nil },
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/cli/cli/v2/api"
|
"github.com/cli/cli/v2/api"
|
||||||
"github.com/cli/cli/v2/internal/ghinstance"
|
"github.com/cli/cli/v2/internal/ghinstance"
|
||||||
"github.com/cli/cli/v2/internal/ghrepo"
|
"github.com/cli/cli/v2/internal/ghrepo"
|
||||||
|
"github.com/cli/cli/v2/internal/prompter"
|
||||||
"github.com/cli/cli/v2/pkg/cmdutil"
|
"github.com/cli/cli/v2/pkg/cmdutil"
|
||||||
|
|
||||||
"github.com/cli/cli/v2/pkg/iostreams"
|
"github.com/cli/cli/v2/pkg/iostreams"
|
||||||
|
|
@ -17,7 +18,7 @@ import (
|
||||||
type DeleteOptions struct {
|
type DeleteOptions struct {
|
||||||
HttpClient func() (*http.Client, error)
|
HttpClient func() (*http.Client, error)
|
||||||
BaseRepo func() (ghrepo.Interface, error)
|
BaseRepo func() (ghrepo.Interface, error)
|
||||||
Prompter cmdutil.Prompter
|
Prompter prompter.Prompter
|
||||||
IO *iostreams.IOStreams
|
IO *iostreams.IOStreams
|
||||||
RepoArg string
|
RepoArg string
|
||||||
Confirmed bool
|
Confirmed bool
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/cli/cli/v2/internal/ghrepo"
|
"github.com/cli/cli/v2/internal/ghrepo"
|
||||||
|
"github.com/cli/cli/v2/internal/prompter"
|
||||||
"github.com/cli/cli/v2/pkg/cmdutil"
|
"github.com/cli/cli/v2/pkg/cmdutil"
|
||||||
"github.com/cli/cli/v2/pkg/httpmock"
|
"github.com/cli/cli/v2/pkg/httpmock"
|
||||||
"github.com/cli/cli/v2/pkg/iostreams"
|
"github.com/cli/cli/v2/pkg/iostreams"
|
||||||
|
|
@ -80,7 +81,7 @@ func Test_deleteRun(t *testing.T) {
|
||||||
tty bool
|
tty bool
|
||||||
opts *DeleteOptions
|
opts *DeleteOptions
|
||||||
httpStubs func(*httpmock.Registry)
|
httpStubs func(*httpmock.Registry)
|
||||||
prompterStubs func(*cmdutil.PrompterMock)
|
prompterStubs func(*prompter.PrompterMock)
|
||||||
wantStdout string
|
wantStdout string
|
||||||
wantErr bool
|
wantErr bool
|
||||||
errMsg string
|
errMsg string
|
||||||
|
|
@ -90,7 +91,7 @@ func Test_deleteRun(t *testing.T) {
|
||||||
tty: true,
|
tty: true,
|
||||||
opts: &DeleteOptions{RepoArg: "OWNER/REPO"},
|
opts: &DeleteOptions{RepoArg: "OWNER/REPO"},
|
||||||
wantStdout: "✓ Deleted repository OWNER/REPO\n",
|
wantStdout: "✓ Deleted repository OWNER/REPO\n",
|
||||||
prompterStubs: func(p *cmdutil.PrompterMock) {
|
prompterStubs: func(p *prompter.PrompterMock) {
|
||||||
p.InputFunc = func(_, _ string) (string, error) {
|
p.InputFunc = func(_, _ string) (string, error) {
|
||||||
return "OWNER/REPO", nil
|
return "OWNER/REPO", nil
|
||||||
}
|
}
|
||||||
|
|
@ -106,7 +107,7 @@ func Test_deleteRun(t *testing.T) {
|
||||||
tty: true,
|
tty: true,
|
||||||
opts: &DeleteOptions{},
|
opts: &DeleteOptions{},
|
||||||
wantStdout: "✓ Deleted repository OWNER/REPO\n",
|
wantStdout: "✓ Deleted repository OWNER/REPO\n",
|
||||||
prompterStubs: func(p *cmdutil.PrompterMock) {
|
prompterStubs: func(p *prompter.PrompterMock) {
|
||||||
p.InputFunc = func(_, _ string) (string, error) {
|
p.InputFunc = func(_, _ string) (string, error) {
|
||||||
return "OWNER/REPO", nil
|
return "OWNER/REPO", nil
|
||||||
}
|
}
|
||||||
|
|
@ -134,7 +135,7 @@ func Test_deleteRun(t *testing.T) {
|
||||||
opts: &DeleteOptions{RepoArg: "REPO"},
|
opts: &DeleteOptions{RepoArg: "REPO"},
|
||||||
wantStdout: "✓ Deleted repository OWNER/REPO\n",
|
wantStdout: "✓ Deleted repository OWNER/REPO\n",
|
||||||
tty: true,
|
tty: true,
|
||||||
prompterStubs: func(p *cmdutil.PrompterMock) {
|
prompterStubs: func(p *prompter.PrompterMock) {
|
||||||
p.InputFunc = func(_, _ string) (string, error) {
|
p.InputFunc = func(_, _ string) (string, error) {
|
||||||
return "OWNER/REPO", nil
|
return "OWNER/REPO", nil
|
||||||
}
|
}
|
||||||
|
|
@ -150,7 +151,7 @@ func Test_deleteRun(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
pm := &cmdutil.PrompterMock{}
|
pm := &prompter.PrompterMock{}
|
||||||
if tt.prompterStubs != nil {
|
if tt.prompterStubs != nil {
|
||||||
tt.prompterStubs(pm)
|
tt.prompterStubs(pm)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/cli/cli/v2/context"
|
"github.com/cli/cli/v2/context"
|
||||||
"github.com/cli/cli/v2/internal/config"
|
"github.com/cli/cli/v2/internal/config"
|
||||||
"github.com/cli/cli/v2/internal/ghrepo"
|
"github.com/cli/cli/v2/internal/ghrepo"
|
||||||
|
"github.com/cli/cli/v2/internal/prompter"
|
||||||
"github.com/cli/cli/v2/pkg/extensions"
|
"github.com/cli/cli/v2/pkg/extensions"
|
||||||
"github.com/cli/cli/v2/pkg/iostreams"
|
"github.com/cli/cli/v2/pkg/iostreams"
|
||||||
)
|
)
|
||||||
|
|
@ -17,25 +18,10 @@ type Browser interface {
|
||||||
Browse(string) error
|
Browse(string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO fix current breaking tests
|
|
||||||
// TODO linter warning for using the prompt package
|
|
||||||
|
|
||||||
//go:generate moq -rm -out prompter_mock.go . Prompter
|
|
||||||
type Prompter interface {
|
|
||||||
Select(string, string, []string) (int, error)
|
|
||||||
MultiSelect(string, string, []string) (int, error)
|
|
||||||
Input(string, string) (string, error)
|
|
||||||
InputHostname() (string, error)
|
|
||||||
Password(string) (string, error)
|
|
||||||
AuthToken() (string, error)
|
|
||||||
Confirm(string, bool) (bool, error)
|
|
||||||
MarkdownEditor(string, string, bool) (string, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Factory struct {
|
type Factory struct {
|
||||||
IOStreams *iostreams.IOStreams
|
IOStreams *iostreams.IOStreams
|
||||||
Browser Browser
|
Browser Browser
|
||||||
Prompter Prompter
|
Prompter prompter.Prompter
|
||||||
|
|
||||||
HttpClient func() (*http.Client, error)
|
HttpClient func() (*http.Client, error)
|
||||||
BaseRepo func() (ghrepo.Interface, error)
|
BaseRepo func() (ghrepo.Interface, error)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue