@@ -5,20 +5,20 @@ import (
5
5
"errors"
6
6
7
7
"github.com/MakeNowJust/heredoc"
8
+ "github.com/anchordotdev/cli/models"
8
9
"github.com/anchordotdev/cli/stacktrace"
9
10
"github.com/anchordotdev/cli/ui"
10
- "github.com/joeshaw/envdecode"
11
- "github.com/mcuadros/go-defaults"
12
11
"github.com/spf13/cobra"
13
12
)
14
13
15
14
type CmdDef struct {
16
15
Name string
17
16
18
- Use string
19
- Args cobra.PositionalArgs
20
- Short string
21
- Long string
17
+ Aliases []string
18
+ Args cobra.PositionalArgs
19
+ Long string
20
+ Short string
21
+ Use string
22
22
23
23
SubDefs []CmdDef
24
24
}
@@ -98,18 +98,19 @@ var rootDef = CmdDef{
98
98
Short : "Audit lcl.host HTTPS Local Development Environment" ,
99
99
},
100
100
{
101
- Name : "clean " ,
101
+ Name : "bootstrap " ,
102
102
103
- Use : "clean [flags]" ,
104
- Args : cobra .NoArgs ,
105
- Short : "Clean lcl.host CA Certificates from the Local Trust Store(s)" ,
103
+ Aliases : []string {"config" },
104
+ Use : "bootstrap [flags]" ,
105
+ Args : cobra .NoArgs ,
106
+ Short : "Initial System Configuration for lcl.host Local Development" ,
106
107
},
107
108
{
108
- Name : "config " ,
109
+ Name : "clean " ,
109
110
110
- Use : "config [flags]" ,
111
+ Use : "clean [flags]" ,
111
112
Args : cobra .NoArgs ,
112
- Short : "Configure System for lcl.host Local Development " ,
113
+ Short : "Clean lcl.host CA Certificates from the Local Trust Store(s) " ,
113
114
},
114
115
{
115
116
Name : "env" ,
@@ -132,6 +133,13 @@ var rootDef = CmdDef{
132
133
Args : cobra .NoArgs ,
133
134
Short : "Setup lcl.host Application" ,
134
135
},
136
+ {
137
+ Name : "trust" ,
138
+
139
+ Use : "trust [flags]" ,
140
+ Args : cobra .NoArgs ,
141
+ Short : "Install CA Certificates for lcl.host Local Development" ,
142
+ },
135
143
},
136
144
},
137
145
{
@@ -232,33 +240,37 @@ func NewCmd[T UIer](parent *cobra.Command, name string, fn func(*cobra.Command))
232
240
}
233
241
234
242
constructor := func () * cobra.Command {
235
- cfg := new (Config )
236
- defaults .SetDefaults (cfg )
237
- if err := envdecode .Decode (cfg ); err != nil && err != envdecode .ErrNoTargetFieldsAreSet {
238
- panic (err )
239
- }
240
-
241
243
cmd := & cobra.Command {
242
- Use : def .Use ,
244
+ Aliases : def .Aliases ,
243
245
Args : def .Args ,
244
- Short : def .Short ,
245
246
Long : def .Long ,
247
+ Short : def .Short ,
248
+ Use : def .Use ,
246
249
SilenceUsage : true ,
247
250
}
248
251
249
- ctx := ContextWithConfig (context .Background (), cfg )
250
- cmd .SetContext (ctx )
251
-
252
252
cmd .SetErrPrefix (ui .Danger ("Error!" ))
253
253
254
+ ctx := ContextWithConfig (context .Background (), defaultConfig ())
255
+ cmd .SetContext (ctx )
256
+
254
257
fn (cmd )
255
258
256
259
cmd .RunE = func (cmd * cobra.Command , args []string ) (returnedError error ) {
257
- cfg := ConfigFromCmd (cmd )
260
+ ctx := cmd .Context ()
261
+
262
+ cfg := new (Config )
263
+ if err := cfg .Load (ctx ); err != nil {
264
+ return err
265
+ }
266
+
258
267
if cfg .Test .SkipRunE {
259
268
return nil
260
269
}
261
270
271
+ ctx = ContextWithConfig (cmd .Context (), cfg )
272
+ cmd .SetContext (ctx )
273
+
262
274
var t T
263
275
264
276
switch any (t ).(type ) {
@@ -270,6 +282,8 @@ func NewCmd[T UIer](parent *cobra.Command, name string, fn func(*cobra.Command))
270
282
ctx , cancel := context .WithCancelCause (cmd .Context ())
271
283
defer cancel (nil )
272
284
285
+ ctx = ContextWithCalledAs (ctx , cmd .CalledAs ())
286
+
273
287
drv , prg := ui .NewDriverTUI (ctx )
274
288
defer func () {
275
289
// release/restore
@@ -288,6 +302,10 @@ func NewCmd[T UIer](parent *cobra.Command, name string, fn func(*cobra.Command))
288
302
errc <- err
289
303
}()
290
304
305
+ if cfg .TOML != nil {
306
+ drv .Activate (ctx , models .ConfigLoaded (cfg .File .Path ))
307
+ }
308
+
291
309
if err := stacktrace .CapturePanic (func () error { return t .UI ().RunTUI (ctx , drv ) }); err != nil {
292
310
var uierr ui.Error
293
311
if errors .As (err , & uierr ) {
0 commit comments