Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] - add prompt #21

Merged
merged 7 commits into from
Dec 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refac huh option
  • Loading branch information
Tanut Lertwarachai authored and Tanut Lertwarachai committed Dec 11, 2024
commit ef2ef8f5e7156190e62f54596ad10748c933e025
20 changes: 13 additions & 7 deletions cmd/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ const (
defaultLabel = "Generate new address (no private key or mnemonic needed)"
)

const (
privateKeyResult = iota
mnemonicResult
defaultResult
)

// keysCmd represents the keys command
func keysCmd(app *relayer.App) *cobra.Command {
cmd := &cobra.Command{
Expand Down Expand Up @@ -53,13 +59,13 @@ $ %s k a eth test-key`, appName, appName)),
privateKey := ""

// Use huh to create a form for user input
selection := ""
selectionPrompt := huh.NewGroup(huh.NewSelect[string]().
selection := 0
selectionPrompt := huh.NewGroup(huh.NewSelect[int]().
Title("Choose how to add a key").
Options(
huh.NewOption(privateKeyLabel, privateKeyLabel),
huh.NewOption(mnemonicLabel, mnemonicLabel),
huh.NewOption(defaultLabel, defaultLabel),
huh.NewOption(privateKeyLabel, privateKeyResult),
huh.NewOption(mnemonicLabel, mnemonicResult),
huh.NewOption(defaultLabel, defaultResult),
).
Value(&selection))

Expand All @@ -70,7 +76,7 @@ $ %s k a eth test-key`, appName, appName)),

// Handle the selected option
switch selection {
case privateKeyLabel:
case privateKeyResult:
privateKeyPrompt := huh.NewGroup(huh.NewInput().
Title("Enter your private key").
Value(&privateKey))
Expand All @@ -80,7 +86,7 @@ $ %s k a eth test-key`, appName, appName)),
return err
}

case mnemonicLabel:
case mnemonicResult:
mnemonicPrompt := huh.NewGroup(huh.NewInput().
Title("Enter your mnemonic").
Value(&mnemonic))
Expand Down
Loading