55 "fmt"
66 "github.com/loft-sh/devspace/cmd/flags"
77 "github.com/loft-sh/devspace/pkg/devspace/build"
8- config2 "github.com/loft-sh/devspace/pkg/devspace/config"
98 "github.com/loft-sh/devspace/pkg/devspace/config/loader"
109 "github.com/loft-sh/devspace/pkg/devspace/config/localcache"
1110 "github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
@@ -27,8 +26,6 @@ import (
2726 "github.com/loft-sh/devspace/pkg/util/interrupt"
2827 "github.com/loft-sh/devspace/pkg/util/log"
2928 "github.com/loft-sh/devspace/pkg/util/message"
30- "github.com/loft-sh/devspace/pkg/util/ptr"
31- "github.com/loft-sh/devspace/pkg/util/survey"
3229 "github.com/pkg/errors"
3330 "github.com/sirupsen/logrus"
3431 "github.com/spf13/cobra"
@@ -62,8 +59,6 @@ type RunPipelineCmd struct {
6259 ForceDeploy bool
6360 SkipDeploy bool
6461
65- Terminal bool
66-
6762 ShowUI bool
6863
6964 // used for testing to allow interruption
@@ -91,7 +86,6 @@ func (cmd *RunPipelineCmd) AddFlags(command *cobra.Command) {
9186 command .Flags ().BoolVar (& cmd .SkipPush , "skip-push" , cmd .SkipPush , "Skips image pushing, useful for minikube deployment" )
9287 command .Flags ().BoolVar (& cmd .SkipPushLocalKubernetes , "skip-push-local-kube" , cmd .SkipPushLocalKubernetes , "Skips image pushing, if a local kubernetes environment is detected" )
9388
94- command .Flags ().BoolVar (& cmd .Terminal , "terminal" , cmd .Terminal , "Open a terminal instead of showing logs" )
9589 command .Flags ().BoolVar (& cmd .ShowUI , "show-ui" , cmd .ShowUI , "Shows the ui server" )
9690}
9791
@@ -110,14 +104,8 @@ func NewRunPipelineCmd(f factory.Factory, globalFlags *flags.GlobalFlags) *cobra
110104#######################################################
111105Execute a pipeline
112106#######################################################` ,
113- Args : cobra .MaximumNArgs ( 1 ) ,
107+ Args : cobra .ArbitraryArgs ,
114108 RunE : func (cobraCmd * cobra.Command , args []string ) error {
115- if len (args ) == 0 && cmd .Pipeline == "" {
116- return fmt .Errorf ("please specify a pipeline through --pipeline or argument" )
117- } else if len (args ) == 1 && cmd .Pipeline == "" {
118- cmd .Pipeline = args [0 ]
119- }
120-
121109 return cmd .Run (cobraCmd , args , f , "run-pipeline" , "runPipelineCommand" )
122110 },
123111 }
@@ -132,6 +120,20 @@ func (cmd *RunPipelineCmd) RunDefault(f factory.Factory) error {
132120
133121// Run executes the command logic
134122func (cmd * RunPipelineCmd ) Run (cobraCmd * cobra.Command , args []string , f factory.Factory , commandName , hookName string ) error {
123+ dashArgs := []string {}
124+ if cobraCmd .ArgsLenAtDash () > - 1 {
125+ dashArgs = args [cobraCmd .ArgsLenAtDash ():]
126+ args = args [:cobraCmd .ArgsLenAtDash ()]
127+ }
128+
129+ if len (args ) > 1 {
130+ return fmt .Errorf ("please specify only 1 pipeline to execute. E.g. devspace run-pipeline my-pipe -- other args" )
131+ } else if len (args ) == 0 && cmd .Pipeline == "" {
132+ return fmt .Errorf ("please specify a pipeline through --pipeline or argument" )
133+ } else if len (args ) == 1 && cmd .Pipeline == "" {
134+ cmd .Pipeline = args [0 ]
135+ }
136+
135137 if cmd .log == nil {
136138 cmd .log = f .GetLog ()
137139 }
@@ -157,15 +159,15 @@ func (cmd *RunPipelineCmd) Run(cobraCmd *cobra.Command, args []string, f factory
157159 }
158160
159161 // set command in context
160- cmd .Ctx = values .WithCommand (cmd .Ctx , commandName )
162+ cmd .Ctx = values .WithFlags (cmd .Ctx , cobraCmd . Flags () )
161163 options := cmd .BuildOptions (cmd .ToConfigOptions ())
162164 ctx , err := initialize (cmd .Ctx , f , false , options , cmd .log )
163165 if err != nil {
164166 return err
165167 }
166168
167169 return runWithHooks (ctx , hookName , func () error {
168- return runPipeline (ctx , options )
170+ return runPipeline (ctx , dashArgs , options )
169171 })
170172}
171173
@@ -176,7 +178,6 @@ type CommandOptions struct {
176178 ConfigOptions * loader.ConfigOptions
177179
178180 Pipeline string
179- Terminal bool
180181 ShowUI bool
181182 UIPort int
182183}
@@ -245,12 +246,6 @@ func initialize(ctx context.Context, f factory.Factory, allowFailingKubeClient b
245246 // add root name to context
246247 ctx = values .WithRootName (ctx , configInterface .Config ().Name )
247248
248- // adjust config
249- err = adjustConfig (configInterface , options , logger )
250- if err != nil {
251- return nil , err
252- }
253-
254249 // create devspace context
255250 devCtx := devspacecontext .NewContext (ctx , configInterface .Variables (), logger ).
256251 WithConfig (configInterface ).
@@ -295,50 +290,6 @@ func updateLastKubeContext(ctx devspacecontext.Context) error {
295290 return nil
296291}
297292
298- func adjustConfig (conf config2.Config , options * CommandOptions , log log.Logger ) error {
299- // check if terminal is enabled
300- c := conf .Config ()
301- if options .Terminal {
302- if len (c .Dev ) == 0 {
303- return errors .New ("No dev config available in DevSpace config" )
304- }
305-
306- devNames := make ([]string , 0 , len (c .Dev ))
307- for k := range c .Dev {
308- devNames = append (devNames , k )
309- }
310-
311- // if only one image exists, use it, otherwise show image picker
312- devName := ""
313- if len (devNames ) == 1 {
314- devName = devNames [0 ]
315- } else {
316- var err error
317- devName , err = log .Question (& survey.QuestionOptions {
318- Question : "Where do you want to open a terminal to?" ,
319- Options : devNames ,
320- })
321- if err != nil {
322- return err
323- }
324- }
325-
326- // adjust dev config
327- for k := range c .Dev {
328- if k == devName {
329- if c .Dev [devName ].Terminal == nil {
330- c .Dev [devName ].Terminal = & latest.Terminal {}
331- }
332- c .Dev [devName ].Terminal .Enabled = ptr .Bool (true )
333- } else {
334- c .Dev [devName ].Terminal = nil
335- }
336- }
337- }
338-
339- return nil
340- }
341-
342293func runWithHooks (ctx devspacecontext.Context , command string , fn func () error ) (err error ) {
343294 err = hook .ExecuteHooks (ctx , nil , command + ":before:execute" )
344295 if err != nil {
@@ -405,13 +356,12 @@ func (cmd *RunPipelineCmd) BuildOptions(configOptions *loader.ConfigOptions) *Co
405356 },
406357 },
407358 ConfigOptions : configOptions ,
408- Terminal : cmd .Terminal ,
409359 Pipeline : cmd .Pipeline ,
410360 ShowUI : cmd .ShowUI ,
411361 }
412362}
413363
414- func runPipeline (ctx devspacecontext.Context , options * CommandOptions ) error {
364+ func runPipeline (ctx devspacecontext.Context , args [] string , options * CommandOptions ) error {
415365 var configPipeline * latest.Pipeline
416366 if ctx .Config ().Config ().Pipelines != nil && ctx .Config ().Config ().Pipelines [options .Pipeline ] != nil {
417367 configPipeline = ctx .Config ().Config ().Pipelines [options .Pipeline ]
@@ -459,7 +409,7 @@ func runPipeline(ctx devspacecontext.Context, options *CommandOptions) error {
459409 defer stderrWriter .Close ()
460410
461411 // start pipeline
462- err = pipe .Run (ctx .WithLogger (log .NewStreamLoggerWithFormat (stdoutWriter , stderrWriter , ctx .Log ().GetLevel (), log .TimeFormat )))
412+ err = pipe .Run (ctx .WithLogger (log .NewStreamLoggerWithFormat (stdoutWriter , stderrWriter , ctx .Log ().GetLevel (), log .TimeFormat )), args )
463413 if err != nil {
464414 return err
465415 }
0 commit comments