Skip to content

Commit 8ba75be

Browse files
committed
refactor: extract struct for input props
1 parent 7cd9c0e commit 8ba75be

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

cmd/create.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,25 @@ func RunCreatePrompts(fs afero.Fs) (CreatePrompts, error) {
6767

6868
switch category {
6969
case "action":
70-
actionRes, actionErr := ui.Input("What is the action?")
70+
actionRes, actionErr := ui.Input(ui.InputProps{Title: "What is the action?"})
7171
if actionErr != nil {
7272
return CreatePrompts{}, actionErr
7373
}
7474

75-
aliasRes, aliasErr := ui.Input(fmt.Sprintf("Alias for (%s).", actionRes))
75+
aliasRes, aliasErr := ui.Input(ui.InputProps{Title: fmt.Sprintf("Alias for (%s).", actionRes)})
7676
if aliasErr != nil {
7777
return CreatePrompts{}, aliasErr
7878
}
7979

8080
cp.aliases = []alias.Alias{{Name: aliasRes, Command: actionRes}}
8181

8282
case "directory":
83-
pathRes, pathErr := ui.Input("What is the path?")
83+
pathRes, pathErr := ui.Input(ui.InputProps{Title: "What is the path?"})
8484
if pathErr != nil {
8585
return CreatePrompts{}, pathErr
8686
}
8787

88-
aliasRes, aliasErr := ui.Input(fmt.Sprintf("Alias for (%s).", pathRes))
88+
aliasRes, aliasErr := ui.Input(ui.InputProps{Title: fmt.Sprintf("Alias for (%s).", pathRes)})
8989
if aliasErr != nil {
9090
return CreatePrompts{}, aliasErr
9191
}
@@ -102,7 +102,7 @@ func RunCreatePrompts(fs afero.Fs) (CreatePrompts, error) {
102102
cp.aliases = []alias.Alias{{Name: aliasRes, Command: pathRes}}
103103

104104
case "parent":
105-
pathRes, pathErr := ui.Input("What is the path?")
105+
pathRes, pathErr := ui.Input(ui.InputProps{Title: "What is the path?"})
106106
if pathErr != nil {
107107
return CreatePrompts{}, pathErr
108108
}
@@ -130,7 +130,7 @@ func RunCreatePrompts(fs afero.Fs) (CreatePrompts, error) {
130130
}
131131

132132
for _, projectPath := range projectPaths {
133-
aliasRes, aliasErr := ui.Input(fmt.Sprintf("Alias for (%s) Leave blank to skip.", projectPath))
133+
aliasRes, aliasErr := ui.Input(ui.InputProps{Title: fmt.Sprintf("Alias for (%s) Leave blank to skip.", projectPath)})
134134
if aliasErr != nil {
135135
return CreatePrompts{}, aliasErr
136136
}

internal/ui/ui.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@ func MultiSelect(title string, options []huh.Option[string]) ([]string, error) {
3232
return value, nil
3333
}
3434

35-
func Input(title string) (string, error) {
36-
var value string
35+
type InputProps struct {
36+
Title string
37+
Value string
38+
}
39+
40+
func Input(ip InputProps) (string, error) {
41+
value := ip.Value
3742
err := huh.NewInput().
38-
Title(title).
43+
Title(ip.Title).
3944
Value(&value).
4045
WithTheme(huh.ThemeBase()).
4146
Run()

0 commit comments

Comments
 (0)