@@ -67,7 +67,7 @@ type RunPipelineCmd struct {
6767 log log.Logger
6868}
6969
70- func (cmd * RunPipelineCmd ) AddFlags ( command * cobra.Command ) {
70+ func (cmd * RunPipelineCmd ) AddPipelineFlags ( f factory. Factory , command * cobra.Command , pipeline * latest. Pipeline ) {
7171 command .Flags ().StringSliceVar (& cmd .SkipDependency , "skip-dependency" , cmd .SkipDependency , "Skips the following dependencies for deployment" )
7272 command .Flags ().StringSliceVar (& cmd .Dependency , "dependency" , cmd .Dependency , "Deploys only the specified named dependencies" )
7373
@@ -87,41 +87,134 @@ func (cmd *RunPipelineCmd) AddFlags(command *cobra.Command) {
8787 command .Flags ().BoolVar (& cmd .SkipPushLocalKubernetes , "skip-push-local-kube" , cmd .SkipPushLocalKubernetes , "Skips image pushing, if a local kubernetes environment is detected" )
8888
8989 command .Flags ().BoolVar (& cmd .ShowUI , "show-ui" , cmd .ShowUI , "Shows the ui server" )
90+
91+ if pipeline != nil {
92+ for _ , pipelineFlag := range pipeline .Flags {
93+ if pipelineFlag .Name == "" {
94+ continue
95+ }
96+
97+ usage := pipelineFlag .Description
98+ if usage == "" {
99+ usage = "Flag " + pipelineFlag .Name
100+ }
101+
102+ var ok bool
103+ if pipelineFlag .Type == "" || pipelineFlag .Type == latest .PipelineFlagTypeBoolean {
104+ val := false
105+ if pipelineFlag .Default != nil {
106+ val , ok = pipelineFlag .Default .(bool )
107+ if ! ok {
108+ f .GetLog ().Errorf ("Error parsing default value for flag %s: %#v is not a boolean" , pipelineFlag .Name , pipelineFlag .Default )
109+ continue
110+ }
111+ }
112+
113+ command .Flags ().BoolP (pipelineFlag .Name , pipelineFlag .Short , val , usage )
114+ } else if pipelineFlag .Type == latest .PipelineFlagTypeString {
115+ val := ""
116+ if pipelineFlag .Default != nil {
117+ val , ok = pipelineFlag .Default .(string )
118+ if ! ok {
119+ f .GetLog ().Errorf ("Error parsing default value for flag %s: %#v is not a string" , pipelineFlag .Name , pipelineFlag .Default )
120+ continue
121+ }
122+ }
123+
124+ command .Flags ().StringP (pipelineFlag .Name , pipelineFlag .Short , val , usage )
125+ } else if pipelineFlag .Type == latest .PipelineFlagTypeInteger {
126+ val := 0
127+ if pipelineFlag .Default != nil {
128+ val , ok = pipelineFlag .Default .(int )
129+ if ! ok {
130+ f .GetLog ().Errorf ("Error parsing default value for flag %s: %#v is not an integer" , pipelineFlag .Name , pipelineFlag .Default )
131+ continue
132+ }
133+ }
134+
135+ command .Flags ().IntP (pipelineFlag .Name , pipelineFlag .Short , val , usage )
136+ } else if pipelineFlag .Type == latest .PipelineFlagTypeStringArray {
137+ val := []string {}
138+ if pipelineFlag .Default != nil {
139+ val , ok = pipelineFlag .Default .([]string )
140+ if ! ok {
141+ f .GetLog ().Errorf ("Error parsing default value for flag %s: %#v is not a string array" , pipelineFlag .Name , pipelineFlag .Default )
142+ continue
143+ }
144+ }
145+
146+ command .Flags ().StringSliceP (pipelineFlag .Name , pipelineFlag .Short , val , usage )
147+ }
148+ }
149+ }
90150}
91151
92152// NewRunPipelineCmd creates a new devspace run-pipeline command
93- func NewRunPipelineCmd (f factory.Factory , globalFlags * flags.GlobalFlags ) * cobra.Command {
153+ func NewRunPipelineCmd (f factory.Factory , globalFlags * flags.GlobalFlags , rawConfig * RawConfig ) * cobra.Command {
94154 cmd := & RunPipelineCmd {
95155 GlobalFlags : globalFlags ,
96156 SkipPushLocalKubernetes : true ,
97157 }
98158 runPipelineCmd := & cobra.Command {
99159 Use : "run-pipeline" ,
100- Short : "Starts the development mode " ,
160+ Short : "Starts a DevSpace pipeline " ,
101161 Long : `
102162#######################################################
103163############## devspace run-pipeline ##################
104164#######################################################
105- Execute a pipeline
165+ Execute a pipeline:
166+ devspace run-pipeline my-pipeline
167+ devspace run-pipeline dev
106168#######################################################` ,
107169 Args : cobra .ArbitraryArgs ,
108170 RunE : func (cobraCmd * cobra.Command , args []string ) error {
109- return cmd .Run (cobraCmd , args , f , "run-pipeline" , " runPipelineCommand" )
171+ return cmd .Run (cobraCmd , args , f , "runPipelineCommand" )
110172 },
111173 }
112174
113- cmd .AddFlags (runPipelineCmd )
175+ if rawConfig != nil && rawConfig .Config != nil {
176+ for _ , pipe := range rawConfig .Config .Pipelines {
177+ runPipelineCmd .AddCommand (NewSpecificPipelineCmd (f , globalFlags , pipe ))
178+ }
179+ }
180+ cmd .AddPipelineFlags (f , runPipelineCmd , nil )
114181 return runPipelineCmd
115182}
116183
184+ // NewSpecificPipelineCmd creates a new devspace render command
185+ func NewSpecificPipelineCmd (f factory.Factory , globalFlags * flags.GlobalFlags , pipeline * latest.Pipeline ) * cobra.Command {
186+ cmd := & RunPipelineCmd {
187+ GlobalFlags : globalFlags ,
188+ SkipPushLocalKubernetes : true ,
189+ Pipeline : pipeline .Name ,
190+ }
191+
192+ specificPipelineCmd := & cobra.Command {
193+ Use : pipeline .Name ,
194+ Short : "Executes pipeline " + pipeline .Name ,
195+ Long : `
196+ #######################################################
197+ ######### devspace run-pipeline ` + pipeline .Name + ` ##########
198+ #######################################################
199+ Executes pipeline ` + pipeline .Name + `
200+ #######################################################` ,
201+ RunE : func (cobraCmd * cobra.Command , args []string ) error {
202+ return cmd .Run (cobraCmd , args , f , "runPipelineCommand" )
203+ },
204+ }
205+
206+ cmd .AddPipelineFlags (f , specificPipelineCmd , pipeline )
207+ return specificPipelineCmd
208+ }
209+
117210func (cmd * RunPipelineCmd ) RunDefault (f factory.Factory ) error {
118- return cmd .Run (nil , nil , f , "run-pipeline" , " runPipelineCommand" )
211+ return cmd .Run (nil , nil , f , "runPipelineCommand" )
119212}
120213
121214// Run executes the command logic
122- func (cmd * RunPipelineCmd ) Run (cobraCmd * cobra.Command , args []string , f factory.Factory , commandName , hookName string ) error {
215+ func (cmd * RunPipelineCmd ) Run (cobraCmd * cobra.Command , args []string , f factory.Factory , hookName string ) error {
123216 dashArgs := []string {}
124- if cobraCmd .ArgsLenAtDash () > - 1 {
217+ if cobraCmd != nil && cobraCmd .ArgsLenAtDash () > - 1 {
125218 dashArgs = args [cobraCmd .ArgsLenAtDash ():]
126219 args = args [:cobraCmd .ArgsLenAtDash ()]
127220 }
@@ -159,7 +252,9 @@ func (cmd *RunPipelineCmd) Run(cobraCmd *cobra.Command, args []string, f factory
159252 }
160253
161254 // set command in context
162- cmd .Ctx = values .WithFlags (cmd .Ctx , cobraCmd .Flags ())
255+ if cobraCmd != nil {
256+ cmd .Ctx = values .WithFlags (cmd .Ctx , cobraCmd .Flags ())
257+ }
163258 options := cmd .BuildOptions (cmd .ToConfigOptions ())
164259 ctx , err := initialize (cmd .Ctx , f , false , options , cmd .log )
165260 if err != nil {
0 commit comments