@@ -10,13 +10,12 @@ import (
1010 "sync"
1111 "time"
1212
13- "github.com/loft-sh/devspace/pkg/devspace/kill"
1413 "github.com/mgutz/ansi"
1514
1615 "github.com/loft-sh/devspace/pkg/devspace/config/loader"
17- "github.com/loft-sh/devspace/pkg/devspace/config/loader/variable/expression"
1816 "github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
1917 "github.com/loft-sh/devspace/pkg/devspace/env"
18+ "github.com/loft-sh/devspace/pkg/devspace/kill"
2019 "github.com/loft-sh/devspace/pkg/util/log"
2120 "github.com/loft-sh/devspace/pkg/util/message"
2221
@@ -34,6 +33,7 @@ import (
3433 "github.com/loft-sh/devspace/cmd/update"
3534 "github.com/loft-sh/devspace/cmd/use"
3635 "github.com/loft-sh/devspace/pkg/devspace/config/loader/variable"
36+ "github.com/loft-sh/devspace/pkg/devspace/config/loader/variable/expression"
3737 "github.com/loft-sh/devspace/pkg/devspace/plugin"
3838 "github.com/loft-sh/devspace/pkg/devspace/upgrade"
3939 "github.com/loft-sh/devspace/pkg/util/exit"
@@ -61,12 +61,7 @@ func NewRootCmd(f factory.Factory) *cobra.Command {
6161 }
6262
6363 log := f .GetLog ()
64- if globalFlags .Silent {
65- log .SetLevel (logrus .FatalLevel )
66- } else if globalFlags .Debug {
67- log .SetLevel (logrus .DebugLevel )
68- }
69-
64+ configureLogLevel (log , globalFlags .Silent , globalFlags .Debug )
7065 ansi .DisableColors (globalFlags .NoColors )
7166
7267 if globalFlags .KubeConfig != "" {
@@ -94,11 +89,7 @@ func NewRootCmd(f factory.Factory) *cobra.Command {
9489 log .Debugf ("Applying extra flags from environment: %s" , strings .Join (extraFlags , " " ))
9590 }
9691
97- if globalFlags .Silent {
98- log .SetLevel (logrus .FatalLevel )
99- } else if globalFlags .Debug {
100- log .SetLevel (logrus .DebugLevel )
101- }
92+ configureLogLevel (log , globalFlags .Silent , globalFlags .Debug )
10293
10394 // call inactivity timeout
10495 if globalFlags .InactivityTimeout > 0 {
@@ -124,6 +115,14 @@ func NewRootCmd(f factory.Factory) *cobra.Command {
124115
125116var globalFlags * flags.GlobalFlags
126117
118+ func configureLogLevel (logger log.Logger , silent , debug bool ) {
119+ if silent {
120+ logger .SetLevel (logrus .FatalLevel )
121+ } else if debug {
122+ logger .SetLevel (logrus .DebugLevel )
123+ }
124+ }
125+
127126// Execute adds all child commands to the root command and sets flags appropriately.
128127// This is called by main.main(). It only needs to happen once to the rootCmd.
129128func Execute () {
@@ -191,6 +190,20 @@ func BuildRoot(f factory.Factory, excludePlugins bool) *cobra.Command {
191190 plugin .SetPlugins (plugins )
192191 }
193192
193+ rootCmd := NewRootCmd (f )
194+ rootCmd .SetHelpCommand (& cobra.Command {
195+ Use : "no-help" ,
196+ Hidden : true ,
197+ })
198+
199+ persistentFlags := rootCmd .PersistentFlags ()
200+ globalFlags = flags .SetGlobalFlags (persistentFlags )
201+
202+ persistentFlags .ParseErrorsAllowlist .UnknownFlags = true
203+ _ = persistentFlags .Parse (os .Args [1 :])
204+
205+ configureLogLevel (f .GetLog (), globalFlags .Silent , globalFlags .Debug )
206+
194207 // try to parse the raw config
195208 var rawConfig * RawConfig
196209
@@ -206,14 +219,6 @@ func BuildRoot(f factory.Factory, excludePlugins bool) *cobra.Command {
206219 }
207220 }
208221
209- // build the root cmd
210- rootCmd := NewRootCmd (f )
211- rootCmd .SetHelpCommand (& cobra.Command {
212- Use : "no-help" ,
213- Hidden : true ,
214- })
215- persistentFlags := rootCmd .PersistentFlags ()
216- globalFlags = flags .SetGlobalFlags (persistentFlags )
217222 kill .SetStopFunction (func (message string ) {
218223 if message == "" {
219224 os .Exit (1 )
@@ -333,7 +338,8 @@ func parseConfig(f factory.Factory) (*RawConfig, error) {
333338 if err != nil {
334339 return nil , err
335340 }
336- configExists , err := configLoader .SetDevSpaceRoot (log .Discard )
341+ logger := f .GetLog ()
342+ configExists , err := configLoader .SetDevSpaceRoot (logger )
337343 if err != nil {
338344 return nil , err
339345 } else if ! configExists {
@@ -349,7 +355,7 @@ func parseConfig(f factory.Factory) (*RawConfig, error) {
349355 }
350356 _ , err = configLoader .LoadWithParser (timeoutCtx , nil , nil , r , & loader.ConfigOptions {
351357 Dry : true ,
352- }, log . Discard )
358+ }, logger )
353359 if r .Resolver != nil {
354360 return r , nil
355361 }
0 commit comments