Skip to content

Commit

Permalink
feat(parameter): add height for the list/multi_list
Browse files Browse the repository at this point in the history
  • Loading branch information
shipengqi committed Apr 28, 2024
1 parent 912fb4a commit ed83029
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,24 +252,26 @@ Properties:

Properties:

| Property | Required | Default Value | Description |
|:--------------|:---------|:--------------|:-------------------------------------------|
| required | no | `false` | Whether a string value is required or not. |
| default_value | no | - | The default value for this item. |
| options | yes | - | The list of options to choose from. |
| Property | Required | Default Value | Description |
|:--------------|:---------|:--------------|:------------------------------------------------------------------------------------------------------|
| required | no | `false` | Whether a string value is required or not. |
| default_value | no | - | The default value for this item. |
| options | yes | - | The list of options to choose from. |
| height | no | - | The height of the list. If the number of options exceeds the height, the list will become scrollable. |

#### multi_list

Similar to `list`, but with multiple selection.

Properties:

| Property | Required | Default Value | Description |
|:--------------|:---------|:--------------|:-------------------------------------------|
| required | no | `false` | Whether a string value is required or not. |
| default_value | no | - | A list of default selection values. |
| options | yes | - | The list of options to choose from. |
| limit | no | `false` | The limit of the multiple selection list. |
| Property | Required | Default Value | Description |
|:--------------|:---------|:--------------|:------------------------------------------------------------------------------------------------------|
| required | no | `false` | Whether a string value is required or not. |
| default_value | no | - | A list of default selection values. |
| options | yes | - | The list of options to choose from. |
| limit | no | `false` | The limit of the multiple selection list. |
| height | no | - | The height of the list. If the number of options exceeds the height, the list will become scrollable. |

#### list/multi_list Options

Expand Down
4 changes: 2 additions & 2 deletions internal/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ items:
- value: test
key: "test: Adding missing or correcting existing tests"
- value: chore
key: "chore: Changes to the build process or auxiliary tools and\n libraries such as documentation generation"
key: "chore: Changes to the build process or auxiliary tools and libraries such as documentation generation"
- value: style
key: "style: Changes that do not affect the meaning of the code\n (white-space, formatting, missing semi-colons, etc)"
key: "style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)"
- value: refactor
key: "refactor: A code change that neither fixes a bug nor adds a feature"
- value: perf
Expand Down
5 changes: 4 additions & 1 deletion internal/parameter/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Param struct {
parameter.Parameter `mapstructure:",squash"`

Options []huh.Option[string] `yaml:"options" json:"options" mapstructure:"options"`
Height *int `yaml:"height" json:"height" mapstructure:"height"`
DefaultValue string `yaml:"default_value" json:"default_value" mapstructure:"default_value"`
Required bool `yaml:"required" json:"required" mapstructure:"required"`
}
Expand All @@ -31,7 +32,9 @@ func (p *Param) Render() {
if len(p.Description) > 0 {
param.Description(p.Description)
}

if p.Height != nil {
param.Height(*p.Height)
}
param.Value(&p.DefaultValue)

var group []validators.Validator[string]
Expand Down
5 changes: 4 additions & 1 deletion internal/parameter/multilist/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Param struct {
DefaultValue []string `yaml:"default_value" json:"default_value" mapstructure:"default_value"`
Required bool `yaml:"required" json:"required" mapstructure:"required"`
Limit *int `yaml:"limit" json:"limit" mapstructure:"limit"`
Height *int `yaml:"height" json:"height" mapstructure:"height"`
}

func (p *Param) Validate() []error {
Expand All @@ -32,7 +33,9 @@ func (p *Param) Render() {
if len(p.Description) > 0 {
param.Description(p.Description)
}

if p.Height != nil {
param.Height(*p.Height)
}
if p.Limit != nil {
param.Limit(*p.Limit)
}
Expand Down

0 comments on commit ed83029

Please sign in to comment.