fix survey invocation

This commit is contained in:
vilmibm 2020-11-13 10:35:32 -08:00
parent 9a20719ec4
commit ef52376fe0
4 changed files with 39 additions and 16 deletions

View file

@ -153,7 +153,12 @@ func TestIssueCreate_nonLegacyTemplate(t *testing.T) {
},
})
// body
as.StubOneDefault()
as.Stub([]*prompt.QuestionStub{
{
Name: "Body",
Default: true,
},
}) // body
// confirm
as.Stub([]*prompt.QuestionStub{
{

View file

@ -433,7 +433,12 @@ func TestPRCreate_nonLegacyTemplate(t *testing.T) {
Value: 0,
},
}) // template
as.StubOneDefault() // body
as.Stub([]*prompt.QuestionStub{
{
Name: "Body",
Default: true,
},
}) // body
as.Stub([]*prompt.QuestionStub{
{
Name: "confirmation",

View file

@ -170,19 +170,25 @@ func BodySurvey(state *IssueMetadataState, templateContent, editorCommand string
state.Body += templateContent
}
p := &surveyext.GhEditor{
BlankAllowed: true,
EditorCommand: editorCommand,
Editor: &survey.Editor{
Message: "Body",
FileName: "*.md",
Default: state.Body,
HideDefault: true,
AppendDefault: true,
// TODO should just be an AskOne but ran into problems with the stubber
qs := []*survey.Question{
{
Name: "Body",
Prompt: &surveyext.GhEditor{
BlankAllowed: true,
EditorCommand: editorCommand,
Editor: &survey.Editor{
Message: "Body",
FileName: "*.md",
Default: state.Body,
HideDefault: true,
AppendDefault: true,
},
},
},
}
err := prompt.SurveyAskOne(p, state)
err := prompt.SurveyAsk(qs, state)
if err != nil {
return err
}
@ -191,12 +197,18 @@ func BodySurvey(state *IssueMetadataState, templateContent, editorCommand string
}
func TitleSurvey(state *IssueMetadataState) error {
p := &survey.Input{
Message: "Title",
Default: state.Title,
// TODO should just be an AskOne but ran into problems with the stubber
qs := []*survey.Question{
{
Name: "Title",
Prompt: &survey.Input{
Message: "Title",
Default: state.Title,
},
},
}
err := prompt.SurveyAskOne(p, state)
err := prompt.SurveyAsk(qs, state)
if err != nil {
return err
}

View file

@ -31,6 +31,7 @@ func InitAskStubber() (*AskStubber, func()) {
}
stubbedPrompt := as.StubOnes[count]
if stubbedPrompt.Default {
// TODO this is failing for basic AskOne invocations with a string result.
defaultValue := reflect.ValueOf(p).Elem().FieldByName("Default")
_ = core.WriteAnswer(response, "", defaultValue)
} else {