1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
diff --git a/main.go b/main.go
index d70562b9cd56a9c98c1ff39832cea7cdc901d878..4d202d3ad1151bc7d3b0a480bc1978df548b6e26 100644
--- a/main.go
+++ b/main.go
@@ -12,8 +12,8 @@ "path/filepath"
"regexp"
"strings"
- "github.com/AlecAivazis/survey/v2"
"github.com/adrg/xdg"
+ "github.com/charmbracelet/huh"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing/transport/http"
@@ -102,27 +102,47 @@ if err != nil {
return fmt.Errorf("could not parse args: %w", err)
}
- if args.username == "" {
- if err := survey.AskOne(&survey.Input{
- Message: "opengist username",
- }, &args.username, survey.WithValidator(survey.Required)); err != nil {
- return fmt.Errorf("opengist username is required: %w", err)
+ required := func(s string) error {
+ if strings.TrimSpace(s) == "" {
+ return errors.New("value is required")
}
+ return nil
+ }
+
+ var prompts []huh.Field
+ if args.username == "" {
+ prompts = append(prompts,
+ huh.NewInput().
+ Title("Opengist username").
+ Validate(required).
+ Value(&args.username),
+ )
}
if args.password == "" && args.passwordFile == "" {
- if err := survey.AskOne(&survey.Password{
- Message: "opengist password",
- }, &args.password, survey.WithValidator(survey.Required)); err != nil {
- return fmt.Errorf("opengist password or password file is required: %w", err)
- }
+ prompts = append(prompts,
+ huh.NewInput().
+ Title("Opengist password").
+ Password(true).
+ Validate(required).
+ Value(&args.password),
+ )
}
if args.domain == "" {
- if err := survey.AskOne(&survey.Input{
- Message: "opengist domain",
- }, &args.domain, survey.WithValidator(survey.Required)); err != nil {
- return fmt.Errorf("opengist domain is required: %w", err)
+ prompts = append(prompts,
+ huh.NewInput().
+ Title("Opengist domain").
+ Validate(required).
+ Value(&args.domain),
+ )
+ }
+
+ if len(prompts) > 0 {
+ if err := huh.NewForm(huh.NewGroup(prompts...)).
+ WithTheme(huh.ThemeCatppuccin()).
+ Run(); err != nil {
+ return fmt.Errorf("missing fields are required: %w", err)
}
}
|