use prompter in shared editable code

This commit is contained in:
Nate Smith 2023-08-16 22:45:06 -05:00
parent a51aba0d22
commit 7860198dd7
4 changed files with 57 additions and 78 deletions

View file

@ -21,10 +21,11 @@ type EditOptions struct {
HttpClient func() (*http.Client, error)
IO *iostreams.IOStreams
BaseRepo func() (ghrepo.Interface, error)
Prompter prShared.EditPrompter
DetermineEditor func() (string, error)
FieldsToEditSurvey func(*prShared.Editable) error
EditFieldsSurvey func(*prShared.Editable, string) error
FieldsToEditSurvey func(prShared.EditPrompter, *prShared.Editable) error
EditFieldsSurvey func(prShared.EditPrompter, *prShared.Editable, string) error
FetchOptions func(*api.Client, ghrepo.Interface, *prShared.Editable) error
SelectorArgs []string
@ -41,6 +42,7 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(*EditOptions) error) *cobra.Comman
FieldsToEditSurvey: prShared.FieldsToEditSurvey,
EditFieldsSurvey: prShared.EditFieldsSurvey,
FetchOptions: prShared.FetchOptions,
Prompter: f.Prompter,
}
var bodyFile string
@ -152,7 +154,7 @@ func editRun(opts *EditOptions) error {
// Prompt the user which fields they'd like to edit.
editable := opts.Editable
if opts.Interactive {
err = opts.FieldsToEditSurvey(&editable)
err = opts.FieldsToEditSurvey(opts.Prompter, &editable)
if err != nil {
return err
}
@ -222,7 +224,7 @@ func editRun(opts *EditOptions) error {
if err != nil {
return err
}
err = opts.EditFieldsSurvey(&editable, editorCommand)
err = opts.EditFieldsSurvey(opts.Prompter, &editable, editorCommand)
if err != nil {
return err
}

View file

@ -511,7 +511,7 @@ func Test_editRun(t *testing.T) {
input: &EditOptions{
SelectorArgs: []string{"123"},
Interactive: true,
FieldsToEditSurvey: func(eo *prShared.Editable) error {
FieldsToEditSurvey: func(p prShared.EditPrompter, eo *prShared.Editable) error {
eo.Title.Edited = true
eo.Body.Edited = true
eo.Assignees.Edited = true
@ -520,7 +520,7 @@ func Test_editRun(t *testing.T) {
eo.Milestone.Edited = true
return nil
},
EditFieldsSurvey: func(eo *prShared.Editable, _ string) error {
EditFieldsSurvey: func(p prShared.EditPrompter, eo *prShared.Editable, _ string) error {
eo.Title.Value = "new title"
eo.Body.Value = "new body"
eo.Assignees.Value = []string{"monalisa", "hubot"}