Skip to content

Commit

Permalink
Support input description to provide more info regarding the input
Browse files Browse the repository at this point in the history
  • Loading branch information
evilmarty committed May 24, 2022
1 parent 9f91380 commit 4faf8b6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ The key `input_name` is a string and its value is a map of the input's
configuration. The name can be used as an argument in the form `-<input_name>`
or `--<input_name>` followed by a value. The input's value is a string.

### `commands.<command_name>.inputs.<input_name>.description`

Optionally describe the input's purpose or outcome.

### `commands.<command_name>.inputs.<input_name>.options`

Limit the value to a list of acceptable values. Options can be a list of values
Expand Down
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type ConfigCommandInput struct {
DefaultValue string `yaml:"default"`
Pattern string
Options ConfigCommandInputOptions
Description string
}

func (cci ConfigCommandInput) Selectable() bool {
Expand Down
1 change: 1 addition & 0 deletions example/ilc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ commands:
description: Give a greeting
inputs:
name:
description: A person's name
default: World
pattern: "^[a-zA-Z]+"
greeting:
Expand Down
11 changes: 8 additions & 3 deletions help.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var (
Width(14)
helpDataListData = lipgloss.NewStyle()
helpDefaultValue = lipgloss.NewStyle().
Foreground(lipgloss.Color("51"))
Foreground(lipgloss.Color("8"))
)

func printHelp(m *model) {
Expand Down Expand Up @@ -120,10 +120,15 @@ func renderInputs(title string, inputs ConfigCommandInputs) string {

items := make([]string, 0, inputsCount*2)
for _, input := range inputs {
desc := ""
desc := input.Description

if input.DefaultValue != "" {
desc = fmt.Sprintf("Default is %s", helpDefaultValue.Render(input.DefaultValue))
defaultDesc := fmt.Sprintf("%s %s", helpDefaultValue.Render("Default is"), helpDefaultValue.Bold(true).Render(input.DefaultValue))
if desc == "" {
desc = defaultDesc
} else {
desc = fmt.Sprintf("%s %s", desc, defaultDesc)
}
}

items = append(
Expand Down

0 comments on commit 4faf8b6

Please sign in to comment.