@@ -33,6 +33,7 @@ func formatToolString(name string, tool Tool) string {
33
33
Foreground (theme .Blurred .MultiSelectSelector .GetForeground ())
34
34
35
35
styledToolName := toolNameStyle .Render (name )
36
+ // TODO: How to handle long descriptions?
36
37
styledDescription := descriptionStyle .Render (tool .Description )
37
38
styledCategories := categoriesStyle .Render (strings .Join (tool .Categories , "," ))
38
39
@@ -63,13 +64,7 @@ func createToolOptions(tools Tools) []huh.Option[string] {
63
64
return options
64
65
}
65
66
66
- func startUI (cfg cliConfig ) {
67
- tools , err := createDefaultTools ()
68
- if err != nil {
69
- logger .Error ("could not parse tools data" , "error" , err )
70
- os .Exit (1 )
71
- }
72
-
67
+ func createForm (cfg cliConfig , tools Tools ) * huh.Form {
73
68
form := huh .NewForm (
74
69
huh .NewGroup (
75
70
huh .NewNote ().
@@ -88,7 +83,6 @@ func startUI(cfg cliConfig) {
88
83
}).
89
84
Value (& workingDir ),
90
85
),
91
-
92
86
huh .NewGroup (
93
87
huh .NewMultiSelect [string ]().
94
88
Title ("Which tools do you want to install?" ).
@@ -104,41 +98,57 @@ func startUI(cfg cliConfig) {
104
98
),
105
99
).WithAccessible (cfg .accessible )
106
100
107
- form .WithTheme (theme )
108
-
109
- err = form .Run ()
110
-
111
- if err != nil {
112
- logger .Fatal (err )
113
- }
101
+ return form
102
+ }
114
103
115
- installDir , err := normalizePath (workingDir )
116
- if err != nil {
117
- logger .Error ("could not normalize path" )
118
- os .Exit (1 )
119
- }
104
+ func process (tools Tools ) func () {
105
+ return func () {
106
+ installDir , err := normalizePath (workingDir )
107
+ if err != nil {
108
+ logger .Error ("could not normalize path" )
109
+ os .Exit (1 )
110
+ }
120
111
121
- start := func () {
122
112
config := newDefaultConfig ()
123
113
if os .Getenv ("WK_EGET_VERSION" ) != "" {
124
114
version := os .Getenv ("WK_EGET_VERSION" )
125
115
logger .Debug ("setting eget version" , "version" , version )
126
116
config .version = version
127
117
}
128
- err : = downloadEgetBinary (installDir , config )
118
+ err = downloadEgetBinary (installDir , config )
129
119
if err != nil {
130
120
logger .Error ("could not download eget binary" , "error" , err )
131
121
os .Exit (1 )
132
122
}
133
123
for _ , t := range selectedTools {
134
124
err = downloadToolWithEget (installDir , tools .Tools [t ])
135
125
if err != nil {
136
- logger .Warn ("could not download tool" , "error" , err )
126
+ logger .Warn ("could not download tool" , "tool" , t , " error" , err )
137
127
continue
138
128
}
139
129
}
130
+ logger .Info (fmt .Sprintf ("Run 'export PATH=$PATH:%s' to add your tools to the PATH" , installDir ))
131
+ }
132
+ }
133
+
134
+ func startUI (cfg cliConfig ) {
135
+ tools , err := createDefaultTools ()
136
+ if err != nil {
137
+ logger .Error ("could not parse tools data" , "error" , err )
138
+ os .Exit (1 )
140
139
}
141
140
141
+ form := createForm (cfg , tools )
142
+
143
+ form .WithTheme (theme )
144
+
145
+ err = form .Run ()
146
+
147
+ if err != nil {
148
+ logger .Fatal (err )
149
+ }
150
+
151
+ start := process (tools )
152
+
142
153
_ = spinner .New ().Title ("Downloading tools ..." ).Accessible (cfg .accessible ).Action (start ).Run ()
143
- logger .Print (fmt .Sprintf ("Run 'export PATH=$PATH:%s' to add your tools to the PATH" , installDir ))
144
154
}
0 commit comments