@@ -11,6 +11,9 @@ type private IsSpecified = bool
1111/// Used to keep registered data for later usage
1212let private runIfOnlySpecifiedPipelines = System.Collections.Generic.List< struct ( IsSpecified * PipelineContext)>()
1313
14+ let private getPipelineIndexes args =
15+ args |> Seq.indexed |> Seq.filter ( fun ( _ , arg ) -> arg = " -p" || arg = " --pipeline" ) |> Seq.map fst |> Seq.toList
16+
1417
1518type PipelineBuilder ( name : string ) =
1619
@@ -244,10 +247,15 @@ type PipelineBuilder(name: string) =
244247 let specified = defaultArg specified true
245248 let ctx = build.Invoke( PipelineContext.Create name)
246249
247- let args = ctx.CmdArgs @ Array.toList ( Environment.GetCommandLineArgs())
250+ let args =
251+ if ctx.RemainingCmdArgs.IsEmpty then
252+ ctx.CmdArgs
253+ else
254+ [ yield ! ctx.CmdArgs; " --" ; yield ! ctx.RemainingCmdArgs ]
255+
248256 let isHelp = args |> Seq.exists ( fun arg -> arg = " -h" || arg = " --help" )
249257 let verbose = args |> Seq.exists ( fun arg -> arg = " -v" || arg = " --verbose" )
250- let pipelineIndex = args |> Seq.tryFindIndex ( fun arg -> arg = " -p " || arg = " --pipeline " )
258+ let pipelineIndexes = getPipelineIndexes args
251259
252260 runIfOnlySpecifiedPipelines.Add( specified, ctx)
253261
@@ -258,18 +266,24 @@ type PipelineBuilder(name: string) =
258266 )
259267
260268 try
261- if isHelp then
262- match pipelineIndex with
263- | Some index when List.length args > index + 1 && ctx.Name.Equals( args[ index + 1 ], StringComparison.OrdinalIgnoreCase) ->
264- ctx.RunCommandHelp( verbose)
265- | _ -> ()
266- else
267- match pipelineIndex with
268- | Some index when List.length args > index + 1 ->
269- if ctx.Name.Equals( args[ index + 1 ], StringComparison.OrdinalIgnoreCase) then
270- ctx.Run()
271- | None when not specified -> ctx.Run()
272- | _ -> ()
269+ match pipelineIndexes with
270+ | [] when not specified -> ctx.Run()
271+ | [] -> ()
272+ | _ :: _ ->
273+ for i, index in Seq.indexed pipelineIndexes do
274+ if List.length args > index + 1 && ctx.Name.Equals( args[ index + 1 ], StringComparison.OrdinalIgnoreCase) then
275+ let args =
276+ if i = Seq.length pipelineIndexes - 1 then
277+ args[ index..]
278+ else
279+ args[ index .. pipelineIndexes[ i + 1 ] - 1 ]
280+ let argInfo = resolveCmdArgsAndRemainings args
281+ let ctx =
282+ { ctx with
283+ CmdArgs = argInfo.CmdArgs
284+ RemainingCmdArgs = argInfo.RemainingArgs
285+ }
286+ if isHelp then ctx.RunCommandHelp( verbose) else ctx.Run()
273287 with
274288 | :? PipelineFailedException
275289 | :? PipelineCancelledException ->
@@ -287,17 +301,18 @@ let inline pipeline name = PipelineBuilder name
287301/// If you only have one specified pipeline, it will try to print its command only help information.
288302let tryPrintPipelineCommandHelp () =
289303 let args = Environment.GetCommandLineArgs()
290- let pipelineIndex = args |> Seq.tryFindIndex ( fun arg -> arg = " -p" || arg = " --pipeline" )
291-
292- match pipelineIndex with
293- | Some index ->
294- let pipelineName = args[ index + 1 ]
295- let isPipelineRegistered =
296- runIfOnlySpecifiedPipelines
297- |> Seq.exists ( fun struct ( _ , x ) -> x.Name.Equals( pipelineName, StringComparison.OrdinalIgnoreCase))
298- if not isPipelineRegistered then
299- AnsiConsole.MarkupLineInterpolated $" Pipeline [red]{pipelineName}[/] is not found."
300- AnsiConsole.MarkupLine " You can use [green]runIfOnlySpecified[/] for your pipline, or check if the name is correct."
304+ let pipelineIndexes = getPipelineIndexes args
305+
306+ match pipelineIndexes with
307+ | _ :: _ ->
308+ for index in pipelineIndexes do
309+ let pipelineName = args[ index + 1 ]
310+ let isPipelineRegistered =
311+ runIfOnlySpecifiedPipelines
312+ |> Seq.exists ( fun struct ( _ , x ) -> x.Name.Equals( pipelineName, StringComparison.OrdinalIgnoreCase))
313+ if not isPipelineRegistered then
314+ AnsiConsole.MarkupLineInterpolated $" Pipeline [red]{pipelineName}[/] is not found."
315+ AnsiConsole.MarkupLine " You can use [green]runIfOnlySpecified[/] for your pipline, or check if the name is correct."
301316
302317 | _ ->
303318 let isHelp = args |> Seq.exists ( fun arg -> arg = " -h" || arg = " --help" )
0 commit comments