Skip to content

Commit dd4a420

Browse files
committed
Updated TestConsole example.
1 parent bc54b89 commit dd4a420

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/TestConsole/Program.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ let main _ =
1010

1111
//ProgramAlt1.run ()
1212
//ProgramNoArgs.run ()
13-
//ProgramNestedSubCommands.run () // Also contains global options
13+
ProgramNestedSubCommands.run () |> Async.AwaitTask |> Async.RunSynchronously // Also contains global options
1414
//ProgramSubCommand.run ()
1515
//ProgramTask.run ()
1616
//ProgramTokenReplacer.SCL.run ()
1717
//ProgramTokenReplacer.run ()
1818
//ProgramExtraInputs.run ()
19-
ProgramAppendWords.run ()
19+
//ProgramAppendWords.run ()

src/TestConsole/ProgramNestedSubCommands.fs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
open System.IO
44
open FSharp.SystemCommandLine
55
open Input
6+
open System.Threading
67

78
module Global =
8-
let enableLogging = option "--enable-logging" |> def false
9-
let logFile = option "--log-file" |> def (FileInfo @"c:\temp\default.log")
9+
let enableLogging = option "--enable-logging" |> recursive |> def false
10+
let logFile = option "--log-file" |> recursive |> def (FileInfo @"c:\temp\default.log")
1011

1112
type Options = { EnableLogging: bool; LogFile: FileInfo }
1213

@@ -64,7 +65,7 @@ let deleteCmd =
6465
let ioCmd =
6566
command "io" {
6667
description "Contains IO related subcommands."
67-
noAction
68+
noAction
6869
addCommands [ deleteCmd; listCmd ]
6970
}
7071

@@ -73,17 +74,18 @@ let main (argv: string[]) =
7374
commandLineConfiguration {
7475
description "Sample app for System.CommandLine"
7576
noAction
76-
addGlobalOptions Global.options
77+
addInputs Global.options
7778
addCommand ioCmd
7879
}
7980

80-
//let parseResult = CommandLineParser.Parse(cfg.RootCommand, argv)
8181
let parseResult = cfg.Parse(argv)
8282

8383
let loggingEnabled = Global.enableLogging.GetValue parseResult
8484
printfn $"ROOT: Logging enabled: {loggingEnabled}"
8585

86-
parseResult.Invoke()
86+
use cts = new CancellationTokenSource()
87+
let parseResult = cfg.Parse(argv)
88+
parseResult.InvokeAsync(cts.Token)
8789

8890
let run () =
8991
"io list \"c:/data/\" --enable-logging" |> Utils.args |> main

0 commit comments

Comments
 (0)