@@ -6,11 +6,11 @@ import (
66 "io"
77 "os"
88 "strings"
9-
9+
1010 "github.com/loft-sh/devspace/pkg/devspace/kubectl"
1111 "github.com/loft-sh/devspace/pkg/devspace/pipeline/env"
1212 "mvdan.cc/sh/v3/expand"
13-
13+
1414 "github.com/loft-sh/devspace/pkg/devspace/config"
1515 "github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
1616 devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
@@ -20,25 +20,25 @@ import (
2020 "github.com/loft-sh/devspace/pkg/util/exit"
2121 "github.com/loft-sh/devspace/pkg/util/interrupt"
2222 "github.com/loft-sh/devspace/pkg/util/log"
23- "github.com/loft-sh/loft-util /pkg/command"
23+ "github.com/loft-sh/utils /pkg/command"
2424 "mvdan.cc/sh/v3/interp"
25-
25+
2626 "github.com/loft-sh/devspace/cmd/flags"
2727 "github.com/loft-sh/devspace/pkg/devspace/config/loader"
2828 "github.com/loft-sh/devspace/pkg/devspace/dependency"
2929 "github.com/loft-sh/devspace/pkg/util/factory"
3030 flagspkg "github.com/loft-sh/devspace/pkg/util/flags"
3131 "github.com/loft-sh/devspace/pkg/util/message"
3232 "github.com/sirupsen/logrus"
33-
33+
3434 "github.com/pkg/errors"
3535 "github.com/spf13/cobra"
3636)
3737
3838// RunCmd holds the run cmd flags
3939type RunCmd struct {
4040 * flags.GlobalFlags
41-
41+
4242 Dependency string
4343 Stdout io.Writer
4444 Stderr io.Writer
@@ -51,7 +51,7 @@ func NewRunCmd(f factory.Factory, globalFlags *flags.GlobalFlags, rawConfig *Raw
5151 Stdout : os .Stdout ,
5252 Stderr : os .Stderr ,
5353 }
54-
54+
5555 runCmd := & cobra.Command {
5656 Use : "run" ,
5757 DisableFlagParsing : true ,
@@ -75,11 +75,11 @@ devspace --dependency my-dependency run any-command --any-command-flag
7575 if err != nil {
7676 return err
7777 }
78-
78+
7979 plugin .SetPluginCommand (cobraCmd , args )
8080 return cmd .RunRun (f , args )
8181 }
82-
82+
8383 if rawConfig != nil && rawConfig .Config != nil {
8484 for _ , cmd := range rawConfig .Config .Commands {
8585 runCmd .AddCommand (NewSpecificRunCommand (cmd ))
@@ -94,20 +94,20 @@ func (cmd *RunCmd) RunRun(f factory.Factory, args []string) error {
9494 if len (args ) == 0 {
9595 return fmt .Errorf ("run requires at least one argument" )
9696 }
97-
97+
9898 // check if dependency command
9999 commandSplitted := strings .Split (args [0 ], "." )
100100 if len (commandSplitted ) > 1 {
101101 cmd .Dependency = strings .Join (commandSplitted [:len (commandSplitted )- 1 ], "." )
102102 args [0 ] = commandSplitted [len (commandSplitted )- 1 ]
103103 }
104-
104+
105105 // Execute plugin hook
106106 err := hook .ExecuteHooks (nil , nil , "run" )
107107 if err != nil {
108108 return err
109109 }
110-
110+
111111 // Set config root
112112 configOptions := cmd .ToConfigOptions ()
113113 configLoader , err := f .NewConfigLoader (cmd .ConfigPath )
@@ -120,45 +120,45 @@ func (cmd *RunCmd) RunRun(f factory.Factory, args []string) error {
120120 } else if ! configExists {
121121 return errors .New (message .ConfigNotFound )
122122 }
123-
123+
124124 // load the config
125125 ctx , err := cmd .LoadCommandsConfig (f , configLoader , configOptions , f .GetLog ())
126126 if err != nil {
127127 return err
128128 }
129-
129+
130130 // check if we should execute a dependency command
131131 if cmd .Dependency != "" {
132132 config , err := configLoader .LoadWithCache (context .Background (), ctx .Config ().LocalCache (), nil , configOptions , f .GetLog ())
133133 if err != nil {
134134 return err
135135 }
136-
136+
137137 ctx = ctx .WithConfig (config )
138138 dependencies , err := f .NewDependencyManager (ctx , configOptions ).ResolveAll (ctx , dependency.ResolveOptions {})
139139 if err != nil {
140140 return err
141141 }
142-
142+
143143 dep := dependency .GetDependencyByPath (dependencies , cmd .Dependency )
144144 if dep == nil {
145145 return fmt .Errorf ("couldn't find dependency %s" , cmd .Dependency )
146146 }
147-
147+
148148 ctx = ctx .AsDependency (dep )
149149 commandConfig , err := findCommand (ctx .Config (), args [0 ])
150150 if err != nil {
151151 return err
152152 }
153-
153+
154154 return executeCommandWithAfter (ctx .Context (), commandConfig , args [1 :], ctx .Config ().Variables (), ctx .WorkingDir (), cmd .Stdout , cmd .Stderr , os .Stdin , ctx .Log ())
155155 }
156-
156+
157157 commandConfig , err := findCommand (ctx .Config (), args [0 ])
158158 if err != nil {
159159 return err
160160 }
161-
161+
162162 return executeCommandWithAfter (ctx .Context (), commandConfig , args [1 :], ctx .Config ().Variables (), ctx .WorkingDir (), cmd .Stdout , cmd .Stderr , os .Stdin , ctx .Log ())
163163}
164164
@@ -167,7 +167,7 @@ func findCommand(config config.Config, name string) (*latest.CommandConfig, erro
167167 if config .Config ().Commands == nil || config .Config ().Commands [name ] == nil {
168168 return nil , errors .Errorf ("couldn't find command '%s' in devspace config" , name )
169169 }
170-
170+
171171 return config .Config ().Commands [name ], nil
172172}
173173
@@ -194,7 +194,7 @@ func executeCommandWithAfter(ctx context.Context, command *latest.CommandConfig,
194194 return errors .Wrap (err , "error executing after command" )
195195 }
196196 }
197-
197+
198198 return originalErr
199199}
200200
@@ -209,28 +209,28 @@ func ParseArgs(cobraCmd *cobra.Command, globalFlags *flags.GlobalFlags, log log.
209209 if index == - 1 {
210210 return nil , fmt .Errorf ("error parsing command: couldn't find %s in command: %v" , cobraCmd .Use , os .Args )
211211 }
212-
212+
213213 // check if is help command
214214 osArgs := os .Args [:index ]
215215 if len (os .Args ) == index + 1 && (os .Args [index ] == "-h" || os .Args [index ] == "--help" ) {
216216 return nil , cobraCmd .Help ()
217217 }
218-
218+
219219 // enable flag parsing
220220 cobraCmd .DisableFlagParsing = false
221-
221+
222222 // apply extra flags
223223 _ , err := flagspkg .ApplyExtraFlags (cobraCmd , osArgs , true )
224224 if err != nil {
225225 return nil , err
226226 }
227-
227+
228228 if globalFlags .Silent {
229229 log .SetLevel (logrus .FatalLevel )
230230 } else if globalFlags .Debug {
231231 log .SetLevel (logrus .DebugLevel )
232232 }
233-
233+
234234 args := os .Args [index :]
235235 return args , nil
236236}
@@ -242,14 +242,14 @@ func (cmd *RunCmd) LoadCommandsConfig(f factory.Factory, configLoader loader.Con
242242 if err != nil {
243243 return nil , err
244244 }
245-
245+
246246 // try to load client
247247 client , err := f .NewKubeClientFromContext (cmd .KubeContext , cmd .Namespace )
248248 if err != nil {
249249 log .Debugf ("Unable to create new kubectl client: %v" , err )
250250 client = nil
251251 }
252-
252+
253253 // verify client connectivity / authn / authz
254254 if client != nil {
255255 // If the current kube context or namespace is different than old,
@@ -260,13 +260,13 @@ func (cmd *RunCmd) LoadCommandsConfig(f factory.Factory, configLoader loader.Con
260260 client = nil
261261 }
262262 }
263-
263+
264264 // Parse commands
265265 commandsInterface , err := configLoader .LoadWithParser (context .Background (), localCache , client , loader .NewCommandsParser (), configOptions , log )
266266 if err != nil {
267267 return nil , err
268268 }
269-
269+
270270 // create context
271271 return devspacecontext .NewContext (context .Background (), commandsInterface .Variables (), log ).
272272 WithKubeClient (client ).
@@ -278,7 +278,7 @@ func executeShellCommand(ctx context.Context, shellCommand string, variables map
278278 for k , v := range variables {
279279 extraEnv [k ] = fmt .Sprintf ("%v" , v )
280280 }
281-
281+
282282 // execute the command in a shell
283283 err := engine .ExecuteSimpleShellCommand (ctx , dir , env .NewVariableEnvProvider (expand .ListEnviron (os .Environ ()... ), extraEnv ), stdout , stderr , stdin , shellCommand , args ... )
284284 if err != nil {
@@ -287,10 +287,10 @@ func executeShellCommand(ctx context.Context, shellCommand string, variables map
287287 ExitCode : int (status ),
288288 }
289289 }
290-
290+
291291 return errors .Wrap (err , "execute command" )
292292 }
293-
293+
294294 return nil
295295}
296296
@@ -299,7 +299,7 @@ func ExecuteCommand(ctx context.Context, cmd *latest.CommandConfig, variables ma
299299 shellCommand := strings .TrimSpace (cmd .Command )
300300 shellArgs := cmd .Args
301301 appendArgs := cmd .AppendArgs
302-
302+
303303 extraEnv := map [string ]string {}
304304 for k , v := range variables {
305305 extraEnv [k ] = fmt .Sprintf ("%v" , v )
@@ -309,11 +309,11 @@ func ExecuteCommand(ctx context.Context, cmd *latest.CommandConfig, variables ma
309309 // Append args to shell command
310310 for _ , arg := range args {
311311 arg = strings .ReplaceAll (arg , "'" , "'\" '\" '" )
312-
312+
313313 shellCommand += " '" + arg + "'"
314314 }
315315 }
316-
316+
317317 // execute the command in a shell
318318 err := engine .ExecuteSimpleShellCommand (ctx , dir , env .NewVariableEnvProvider (expand .ListEnviron (os .Environ ()... ), extraEnv ), stdout , stderr , stdin , shellCommand , args ... )
319319 if err != nil {
@@ -322,24 +322,24 @@ func ExecuteCommand(ctx context.Context, cmd *latest.CommandConfig, variables ma
322322 ExitCode : int (status ),
323323 }
324324 }
325-
325+
326326 return errors .Wrap (err , "execute command" )
327327 }
328-
328+
329329 return nil
330330 }
331-
331+
332332 shellArgs = append (shellArgs , args ... )
333333 return command .Command (ctx , dir , env .NewVariableEnvProvider (expand .ListEnviron (os .Environ ()... ), extraEnv ), stdout , stderr , stdin , shellCommand , shellArgs ... )
334334}
335335
336336// RunCommandCmd holds the cmd flags of a run command
337337type RunCommandCmd struct {
338338 * flags.GlobalFlags
339-
339+
340340 Command * latest.CommandConfig
341341 Variables map [string ]interface {}
342-
342+
343343 Stdout io.Writer
344344 Stderr io.Writer
345345}
@@ -357,7 +357,7 @@ func NewSpecificRunCommand(command *latest.CommandConfig) *cobra.Command {
357357 description = description [:61 ] + "..."
358358 }
359359 }
360-
360+
361361 runCmd := & cobra.Command {
362362 Use : command .Name ,
363363 Short : description ,
0 commit comments