Skip to content

Commit a5d4653

Browse files
committed
Refactored TestConsole so inputs are contained within test module.
1 parent 5c17b2a commit a5d4653

File tree

11 files changed

+57
-21
lines changed

11 files changed

+57
-21
lines changed

src/TestConsole/Program.fs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ let args commandLine =
88
[<EntryPoint>]
99
let main _ =
1010

11-
//ProgramAlt1.main (args "--int-option 1 --bool-option true --file-option \"c:\test\"")
12-
//ProgramNoArgs.main (args "")
13-
//ProgramNestedSubCommands.main (args "io list \"c:/data/\" --enable-logging") // Also contains global options
14-
//ProgramSubCommand.main (args "list c:/data/")
15-
//ProgramSubCommand.main (args "delete c:/data/ --recursive")
16-
//ProgramTask.main (args "-w hello -w world")
17-
//ProgramTokenReplacer.SCL.main (args "--package @shoelace-style/shoelace")
18-
ProgramTokenReplacer.main (args "get @shoelace-style/shoelace")
19-
//ProgramExtraInputs.main (args "-a A -b B -c C -d D -e E -1 1 -2 2 -3 3 -4 4 -5 5")
20-
//ProgramAppendWords.main (args "-w hello -w world -s \", \"")
11+
//ProgramAlt1.run ()
12+
//ProgramNoArgs.run ()
13+
//ProgramNestedSubCommands.run () // Also contains global options
14+
//ProgramSubCommand.run ()
15+
//ProgramTask.run ()
16+
//ProgramTokenReplacer.SCL.run ()
17+
//ProgramTokenReplacer.run ()
18+
//ProgramExtraInputs.run ()
19+
ProgramAppendWords.run ()

src/TestConsole/ProgramAlt1.fs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,7 @@ let main (argv: string[]) =
3030

3131
cmd.Parse(argv).InvokeAsync()
3232
|> Async.AwaitTask
33-
|> Async.RunSynchronously
33+
|> Async.RunSynchronously
34+
35+
let run () =
36+
"--int-option 1 --bool-option true --file-option \"c:\test\"" |> Utils.args |> main

src/TestConsole/ProgramAppendWords.fs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@ open FSharp.SystemCommandLine
44
open Input
55

66
let app (words: string array, separator: string option) =
7-
let separator = separator |> Option.defaultValue ", "
7+
let separator = defaultArg separator " + "
88
System.String.Join(separator, words) |> printfn "Result: %s"
99

1010
let main argv =
11-
//let words = Input.Option("word", ["--word"; "-w"], Array.empty, "A list of words to be appended")
12-
//let separator = Input.OptionMaybe("separator", ["--separator"; "-s"], "A character that will separate the joined words.")
13-
let words = option "--word" |> alias "-w" |> desc "A list of words to be appended"
14-
let separator = optionMaybe "--separator" |> alias "-s" |> desc "A character that will separate the joined words."
15-
1611
rootCommand argv {
1712
description "Appends words together"
18-
inputs (words, separator)
13+
inputs (
14+
option "--word"
15+
|> alias "-w"
16+
|> desc "A list of words to be appended"
17+
|> acceptOnlyFromAmong [ "hello" ; "world" ],
18+
19+
optionMaybe "--separator"
20+
|> alias "-s"
21+
|> desc "A character that will separate the joined words."
22+
)
1923
setAction app
20-
}
24+
}
25+
26+
let run () =
27+
"-w hello -w world -s \", \"" |> Utils.args |> main
28+

src/TestConsole/ProgramExtraInputs.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ let main argv =
3939
setAction app
4040
addInputs [ a; b; c; d; e; f; g; h; i; j ]
4141
}
42+
43+
let run () =
44+
"-a A -b B -c C -d D -e E -1 1 -2 2 -3 3 -4 4 -5 5" |> Utils.args |> main

src/TestConsole/ProgramNestedSubCommands.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,7 @@ let main (argv: string[]) =
8484
printfn $"ROOT: Logging enabled: {loggingEnabled}"
8585

8686
parseResult.Invoke()
87+
88+
let run () =
89+
"io list \"c:/data/\" --enable-logging" |> Utils.args |> main
8790

src/TestConsole/ProgramNoArgs.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ let main argv =
1010
description "My sample app"
1111
setAction app
1212
}
13-
13+
14+
let run () =
15+
"" |> Utils.args |> main
1416

src/TestConsole/ProgramSubCommand.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@ let main argv =
4646
noAction
4747
addCommands [ listCmd; deleteCmd ]
4848
}
49+
50+
let run () =
51+
"list c:/data/" |> Utils.args |> main

src/TestConsole/ProgramTask.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ let main argv =
2929
}
3030
|> Async.AwaitTask
3131
|> Async.RunSynchronously
32+
33+
let run () =
34+
"-w hello -w world" |> Utils.args |> main

src/TestConsole/ProgramTokenReplacer.fs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ module SCL =
2020

2121
cmd.Parse(argv, cfg).Invoke()
2222

23+
let run () =
24+
"--package @shoelace-style/shoelace" |> Utils.args |> main
25+
2326

2427
open FSharp.SystemCommandLine
2528
open Input
26-
open System.CommandLine.Parsing
2729

2830
let getCmd =
2931
command "get" {
@@ -52,3 +54,6 @@ let main argv =
5254
noAction
5355
addCommand getCmd
5456
}
57+
58+
let run () =
59+
"get @shoelace-style/shoelace" |> Utils.args |> main

src/TestConsole/TestConsole.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9+
<Compile Include="Utils.fs" />
910
<Compile Include="ProgramAlt1.fs" />
1011
<Compile Include="ProgramNoArgs.fs" />
1112
<Compile Include="ProgramNestedSubCommands.fs" />

0 commit comments

Comments
 (0)