@@ -2,14 +2,25 @@ package commands
22
33import (
44 "fmt"
5+ "github.com/jessevdk/go-flags"
6+ "github.com/loft-sh/devspace/pkg/devspace/config"
7+ "github.com/loft-sh/devspace/pkg/devspace/config/versions"
8+ "github.com/loft-sh/devspace/pkg/devspace/config/versions/util"
59 devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
610 "github.com/loft-sh/devspace/pkg/devspace/pipeline/engine"
711 enginetypes "github.com/loft-sh/devspace/pkg/devspace/pipeline/engine/types"
812 "github.com/loft-sh/devspace/pkg/devspace/pipeline/types"
13+ "github.com/loft-sh/devspace/pkg/util/strvals"
14+ "github.com/pkg/errors"
915 "io"
1016 "mvdan.cc/sh/v3/interp"
1117)
1218
19+ type RunDefaultPipelineOptions struct {
20+ Set []string `long:"set" description:"Set configuration"`
21+ SetString []string `long:"set-string" description:"Set configuration as string"`
22+ }
23+
1324type NewHandlerFn func (ctx devspacecontext.Context , stdout , stderr io.Writer , pipeline types.Pipeline ) enginetypes.ExecHandler
1425
1526func RunDefaultPipeline (ctx devspacecontext.Context , pipeline types.Pipeline , args []string , newHandler NewHandlerFn ) error {
@@ -19,10 +30,24 @@ func RunDefaultPipeline(ctx devspacecontext.Context, pipeline types.Pipeline, ar
1930 }
2031
2132 hc := interp .HandlerCtx (ctx .Context ())
33+
34+ options := & RunDefaultPipelineOptions {}
35+ args , err = flags .ParseArgs (options , args )
36+ if err != nil {
37+ return errors .Wrap (err , "parse args" )
38+ }
39+
2240 if len (args ) != 1 {
2341 return fmt .Errorf ("usage: run_default_pipeline [pipeline]" )
2442 }
2543
44+ if len (args ) > 0 {
45+ ctx , err = applyPipelineSetValue (ctx , options .Set , options .SetString )
46+ if err != nil {
47+ return err
48+ }
49+ }
50+
2651 defaultPipeline , err := types .GetDefaultPipeline (args [0 ])
2752 if err != nil {
2853 return err
@@ -31,3 +56,45 @@ func RunDefaultPipeline(ctx devspacecontext.Context, pipeline types.Pipeline, ar
3156 _ , err = engine .ExecutePipelineShellCommand (ctx .Context (), defaultPipeline .Run , nil , hc .Dir , false , hc .Stdout , hc .Stderr , hc .Stdin , hc .Env , newHandler (ctx , hc .Stdout , hc .Stderr , pipeline ))
3257 return err
3358}
59+
60+ func applyPipelineSetValue (ctx devspacecontext.Context , set , setString []string ) (devspacecontext.Context , error ) {
61+ if len (set ) == 0 && len (setString ) == 0 {
62+ return ctx , nil
63+ }
64+
65+ rawConfigOriginal := ctx .Config ().RawBeforeConversion ()
66+ rawConfig := map [string ]interface {}{}
67+ err := util .Convert (rawConfigOriginal , & rawConfig )
68+ if err != nil {
69+ return nil , err
70+ }
71+
72+ for _ , s := range set {
73+ err = strvals .ParseInto (s , rawConfig )
74+ if err != nil {
75+ return nil , errors .Wrap (err , "parsing --set flag" )
76+ }
77+ }
78+
79+ for _ , s := range setString {
80+ err = strvals .ParseIntoString (s , rawConfig )
81+ if err != nil {
82+ return nil , errors .Wrap (err , "parsing --set-string flag" )
83+ }
84+ }
85+
86+ latestConfig , err := versions .Parse (rawConfig , ctx .Log ())
87+ if err != nil {
88+ return nil , err
89+ }
90+
91+ return ctx .WithConfig (config .NewConfig (
92+ ctx .Config ().Raw (),
93+ rawConfig ,
94+ latestConfig ,
95+ ctx .Config ().LocalCache (),
96+ ctx .Config ().RemoteCache (),
97+ ctx .Config ().Variables (),
98+ ctx .Config ().Path (),
99+ )), nil
100+ }
0 commit comments