File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -194,6 +194,18 @@ type ParseResult<'Template when 'Template :> IArgParserTemplate>
194194 member r.IterResult ( expr : Expr < 'Field -> 'Template >, iterator : 'Field -> unit , ? source ) : unit =
195195 expr |> tryGetResult source |> Option.iter ( parseResult iterator)
196196
197+ /// <summary >
198+ /// Attempts to recover the subcommand parameter from the results,
199+ /// if once has been specified.
200+ /// </summary >
201+ member r.TryGetSubCommand () : 'Template option =
202+ results.Cases
203+ |> Seq.concat
204+ |> Seq.tryPick( fun c ->
205+ if c.ArgInfo.Type = ArgumentType.SubCommand then
206+ Some( c.Value :?> 'Template)
207+ else None)
208+
197209 override r.ToString () = sprintf " %A " ( r.GetAllResults())
198210
199211 // used by StructuredFormatDisplay attribute
Original file line number Diff line number Diff line change 186186 <ItemGroup >
187187 <Reference Include =" FSharp.Core" >
188188 <HintPath >..\..\packages\FSharp.Core\lib\net40\FSharp.Core.dll</HintPath >
189- <Private >True </Private >
189+ <Private >False </Private >
190190 <Paket >True</Paket >
191191 </Reference >
192192 </ItemGroup >
Original file line number Diff line number Diff line change @@ -229,13 +229,15 @@ module ``Argu Tests`` =
229229 let args = [| " push" ; " --remote" ; " origin" ; " --branch" ; " master" |]
230230 let results = parser.ParseCommandLine( args, ignoreMissing = true )
231231 let nested = results.GetResult <@ Push @>
232+ test <@ match results.TryGetSubCommand() with Some ( Push _) -> true | _ -> false @>
232233 test <@ nested.GetAllResults() = [ Remote " origin" ; Branch " master" ] @>
233234
234235 [<Fact>]
235236 let ``Simple subcommand parsing 2`` () =
236237 let args = [| " clean" ; " -fdx" |]
237238 let results = parser.ParseCommandLine( args, ignoreMissing = true )
238239 let nested = results.GetResult <@ Clean @>
240+ test <@ match results.TryGetSubCommand() with Some ( Clean _) -> true | _ -> false @>
239241 test <@ nested.GetAllResults() = [ F; D; X] @>
240242
241243 [<Fact>]
You can’t perform that action at this time.
0 commit comments