-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate to huh for query engine (#129)
* migrate to huh engine * add new support for looped text input * additional group of input features
- Loading branch information
Showing
20 changed files
with
1,237 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
messages: | ||
pre: | | ||
# Example Prompts | ||
This is an example of all the prompts available in the CLI. | ||
post: | | ||
# All Set | ||
You're Done! | ||
- Input: {{ .Scaffold.input }} (type={{ typeOf .Scaffold.input }}) | ||
- Looped: {{ .Scaffold.looped | join ", " }} (type={{ typeOf .Scaffold.looped }}) | ||
- Multiline: {{ .Scaffold.multiline }} (type={{ typeOf .Scaffold.multiline }}) | ||
- Single Select: {{ .Scaffold.singleselect }} (type={{ typeOf .Scaffold.singleselect }}) | ||
- Multi Select: {{ .Scaffold.multiselect | join ", " }} (type={{ typeOf .Scaffold.multiselect }}) | ||
- Confirm: {{ .Scaffold.confirm }} (type={{ typeOf .Scaffold.confirm }}) | ||
questions: | ||
- name: "input" | ||
group: inputs | ||
prompt: | ||
message: "Basic Input" | ||
description: "This is a basic text input" | ||
required: true | ||
- name: "looped" | ||
group: "inputs" | ||
prompt: | ||
message: "Looped Input" | ||
description: "This is a looped input, submit empty value to stop looping" | ||
loop: true | ||
required: true | ||
- name: "multiline" | ||
group: "inputs" | ||
prompt: | ||
message: "Multiline Input" | ||
multi: true | ||
required: true | ||
- name: "hidden" | ||
group: "hidden" | ||
when: '{{ eq .input "hidden" }}' | ||
prompt: | ||
message: "Hidden Input" | ||
description: "This input group is shown conditionally" | ||
- name: "singleselect" | ||
group: selects | ||
prompt: | ||
message: "Single Select" | ||
description: "This is a single select prompt" | ||
default: ["Option 2"] | ||
options: | ||
- "Option 1" | ||
- "Option 2" | ||
- "Option 3" | ||
- "Option 4" | ||
required: true | ||
- name: "multiselect" | ||
group: selects | ||
prompt: | ||
message: "Multi Select" | ||
description: "This is a multi select prompt" | ||
multi: true | ||
default: ["Option 4"] | ||
options: | ||
- "Option 1" | ||
- "Option 2" | ||
- "Option 3" | ||
- "Option 4" | ||
required: true | ||
- name: "confirm" | ||
group: confirms | ||
prompt: | ||
message: "Confirm" | ||
description: "This is a confirm prompt" | ||
confirm: true | ||
required: true |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package scaffold | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/charmbracelet/huh" | ||
"github.com/charmbracelet/lipgloss" | ||
"github.com/hay-kot/scaffold/app/core/engine" | ||
) | ||
|
||
type Askable struct { | ||
Name string | ||
Key string | ||
Hook func(vars engine.Vars) error | ||
Field huh.Field | ||
} | ||
|
||
func NewAskable(name string, key string, field huh.Field, fn func(vars engine.Vars) error) *Askable { | ||
return &Askable{ | ||
Name: name, | ||
Key: key, | ||
Field: field, | ||
Hook: fn, | ||
} | ||
} | ||
|
||
var ( | ||
bold = lipgloss.NewStyle().Bold(true).Render | ||
light = lipgloss.NewStyle().Foreground(lipgloss.Color("#FF83D5")).Render | ||
base = lipgloss.NewStyle().Foreground(lipgloss.Color("#6C74FD")).Render | ||
) | ||
|
||
func (a *Askable) String() string { | ||
bldr := strings.Builder{} | ||
|
||
bldr.WriteString(" ") | ||
bldr.WriteString(light("?")) | ||
bldr.WriteString(" ") | ||
bldr.WriteString(bold(a.Name)) | ||
bldr.WriteString(" ") | ||
|
||
val := a.Field.GetValue() | ||
|
||
switch v := val.(type) { | ||
case string: | ||
if v == "" { | ||
return "" | ||
} | ||
|
||
if strings.Contains(v, "\n") { | ||
bldr.WriteString(base("|")) | ||
|
||
for _, line := range strings.Split(v, "\n") { | ||
bldr.WriteString("\n") | ||
bldr.WriteString(" ") | ||
bldr.WriteString(base(line)) | ||
} | ||
|
||
break | ||
} | ||
|
||
bldr.WriteString(base(v)) | ||
case []string: | ||
if len(v) == 0 { | ||
return "" | ||
} | ||
|
||
for _, v := range v { | ||
bldr.WriteString("\n") | ||
bldr.WriteString(" - ") | ||
bldr.WriteString(base(v)) | ||
} | ||
case bool: | ||
if v { | ||
bldr.WriteString(base("true")) | ||
} else { | ||
bldr.WriteString(base("false")) | ||
} | ||
|
||
default: | ||
bldr.WriteString("unknown type, please report this issue to the scaffold maintainer.") | ||
} | ||
|
||
bldr.WriteString("\n") | ||
|
||
return bldr.String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.