Skip to content

Commit

Permalink
feat: option description as survey help
Browse files Browse the repository at this point in the history
  • Loading branch information
mumoshu committed Feb 11, 2020
1 parent 5081055 commit 6d8c6fd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 4 additions & 0 deletions examples/options/options.variant
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
option "int1" {
type = number
description = "The number to be referenced by $${opt.int1} e.g. 1, 2"
}

option "ints1" {
type = list(number)
description = "The list of numbers to be referenced by $${opt.ints1} e.g. 1<NEWLINE>2<NEWLINE>"
}

option "str1" {
type = string
description = "The string to be referenced by $${opt.sr1} e.g. a, b"
}

option "strs1" {
type = list(string)
description = "The list of strings to be referenced by $${opt.strs1} e.g. b<NEWLINE>c<NEWLINE>"
}

job "test" {
Expand Down
13 changes: 9 additions & 4 deletions pkg/app/survey.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ func makeQuestions(pendingOptions []PendingOption) ([]*survey.Question, map[stri

var msg string

var description string

if op.Spec.Description != nil {
msg = *op.Spec.Description
} else {
msg = name
description = *op.Spec.Description
}

msg = msg + "?"
msg = name

var validate survey.Validator

Expand All @@ -43,10 +43,12 @@ func makeQuestions(pendingOptions []PendingOption) ([]*survey.Question, map[stri
case cty.String:
prompt = &survey.Input{
Message: msg,
Help: description,
}
case cty.Number:
prompt = &survey.Input{
Message: msg,
Help: description,
}

transform = func(ans interface{}) (newAns interface{}) {
Expand All @@ -69,11 +71,13 @@ func makeQuestions(pendingOptions []PendingOption) ([]*survey.Question, map[stri
case cty.Bool:
prompt = &survey.Confirm{
Message: msg,
Help: description,
Default: false,
}
case cty.List(cty.String):
prompt = &survey.Multiline{
Message: msg,
Help: description,
}

transform = func(ans interface{}) (newAns interface{}) {
Expand All @@ -93,6 +97,7 @@ func makeQuestions(pendingOptions []PendingOption) ([]*survey.Question, map[stri
case cty.List(cty.Number):
prompt = &survey.Multiline{
Message: msg,
Help: description,
}

transform = func(ans interface{}) (newAns interface{}) {
Expand Down

0 comments on commit 6d8c6fd

Please sign in to comment.