@@ -5,20 +5,20 @@ import (
55 "errors"
66
77 "github.com/MakeNowJust/heredoc"
8+ "github.com/anchordotdev/cli/models"
89 "github.com/anchordotdev/cli/stacktrace"
910 "github.com/anchordotdev/cli/ui"
10- "github.com/joeshaw/envdecode"
11- "github.com/mcuadros/go-defaults"
1211 "github.com/spf13/cobra"
1312)
1413
1514type CmdDef struct {
1615 Name string
1716
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
2222
2323 SubDefs []CmdDef
2424}
@@ -98,18 +98,19 @@ var rootDef = CmdDef{
9898 Short : "Audit lcl.host HTTPS Local Development Environment" ,
9999 },
100100 {
101- Name : "clean " ,
101+ Name : "bootstrap " ,
102102
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" ,
106107 },
107108 {
108- Name : "config " ,
109+ Name : "clean " ,
109110
110- Use : "config [flags]" ,
111+ Use : "clean [flags]" ,
111112 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) " ,
113114 },
114115 {
115116 Name : "env" ,
@@ -132,6 +133,13 @@ var rootDef = CmdDef{
132133 Args : cobra .NoArgs ,
133134 Short : "Setup lcl.host Application" ,
134135 },
136+ {
137+ Name : "trust" ,
138+
139+ Use : "trust [flags]" ,
140+ Args : cobra .NoArgs ,
141+ Short : "Install CA Certificates for lcl.host Local Development" ,
142+ },
135143 },
136144 },
137145 {
@@ -232,33 +240,37 @@ func NewCmd[T UIer](parent *cobra.Command, name string, fn func(*cobra.Command))
232240 }
233241
234242 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-
241243 cmd := & cobra.Command {
242- Use : def .Use ,
244+ Aliases : def .Aliases ,
243245 Args : def .Args ,
244- Short : def .Short ,
245246 Long : def .Long ,
247+ Short : def .Short ,
248+ Use : def .Use ,
246249 SilenceUsage : true ,
247250 }
248251
249- ctx := ContextWithConfig (context .Background (), cfg )
250- cmd .SetContext (ctx )
251-
252252 cmd .SetErrPrefix (ui .Danger ("Error!" ))
253253
254+ ctx := ContextWithConfig (context .Background (), defaultConfig ())
255+ cmd .SetContext (ctx )
256+
254257 fn (cmd )
255258
256259 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+
258267 if cfg .Test .SkipRunE {
259268 return nil
260269 }
261270
271+ ctx = ContextWithConfig (cmd .Context (), cfg )
272+ cmd .SetContext (ctx )
273+
262274 var t T
263275
264276 switch any (t ).(type ) {
@@ -270,6 +282,8 @@ func NewCmd[T UIer](parent *cobra.Command, name string, fn func(*cobra.Command))
270282 ctx , cancel := context .WithCancelCause (cmd .Context ())
271283 defer cancel (nil )
272284
285+ ctx = ContextWithCalledAs (ctx , cmd .CalledAs ())
286+
273287 drv , prg := ui .NewDriverTUI (ctx )
274288 defer func () {
275289 // release/restore
@@ -288,6 +302,10 @@ func NewCmd[T UIer](parent *cobra.Command, name string, fn func(*cobra.Command))
288302 errc <- err
289303 }()
290304
305+ if cfg .TOML != nil {
306+ drv .Activate (ctx , models .ConfigLoaded (cfg .File .Path ))
307+ }
308+
291309 if err := stacktrace .CapturePanic (func () error { return t .UI ().RunTUI (ctx , drv ) }); err != nil {
292310 var uierr ui.Error
293311 if errors .As (err , & uierr ) {
0 commit comments