Skip to content

Commit f523d4c

Browse files
Refactor the project cracker into a new file et al. (#618)
* Move some code from BuildCommand.fs to a new file. Do not report nonexistent substitution parameters (see changes in the param function of ProjectCracker.fs). * Fix and document the --parameters command line option. Seq.pairwise [1;2;3;4] returns [1,2; 2,3; 3,4], not [1,2; 3,4]. * Remove a try-with block around File.Exists (it doesn't throw). And use Process.Start with UseShellExecute on all platforms (it is implemented on .NET Core). * Use System.Text.Json to serialize the documentation search index. Remove duplicate code in a helper function in BuildCommand.fs. * Update packages. * Make some optimizations in the project cracker. The most important is the replacement of the tree-based FSharpMap with the hashtable-based readOnlyDict. * Exit without leaving a stacktrace if --parameters was incorrectly defined. * Do not catch and then print exceptions at the entry point; let them be thrown. It is not needed. They will already be reported to the console and AggregateExceptions are not correctly handled.
1 parent 60cb2cf commit f523d4c

File tree

11 files changed

+649
-937
lines changed

11 files changed

+649
-937
lines changed

.config/dotnet-tools.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"isRoot": true,
44
"tools": {
55
"fake-cli": {
6-
"version": "5.20.0",
6+
"version": "5.20.3",
77
"commands": [
88
"fake"
99
]
1010
},
1111
"paket": {
12-
"version": "5.245.2",
12+
"version": "5.249.0",
1313
"commands": [
1414
"paket"
1515
]

paket.dependencies

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version 5.247.4
1+
version 5.249.0
22
source https://api.nuget.org/v3/index.json
33
framework: auto-detect
44
storage: none
@@ -9,7 +9,7 @@ nuget CommandLineParser ~> 2.8
99
nuget Dotnet.ProjInfo
1010
nuget Dotnet.ProjInfo.Workspace
1111
nuget Newtonsoft.Json
12-
nuget Suave 2.1.1
12+
nuget Suave
1313
nuget System.Memory
1414

1515
# Used to create notebook docs with mybinder links that work

paket.lock

Lines changed: 190 additions & 469 deletions
Large diffs are not rendered by default.

src/FSharp.Formatting.CommandTool/BuildCommand.fs

Lines changed: 18 additions & 433 deletions
Large diffs are not rendered by default.

src/FSharp.Formatting.CommandTool/FSharp.Formatting.CommandTool.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<Link>Common\AssemblyInfo.fs</Link>
1717
</Compile>
1818
<Compile Include="Options.fs" />
19+
<Compile Include="ProjectCracker.fs" />
1920
<Compile Include="BuildCommand.fs" />
2021
<Compile Include="Program.fs" />
2122
</ItemGroup>

src/FSharp.Formatting.CommandTool/Options.fs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,20 @@ module Common =
99
| Some "" -> None
1010
| _ -> Some (List.ofSeq a)
1111

12+
// https://stackoverflow.com/questions/4126351
13+
let private pairs (xs: _ seq) = seq {
14+
use enumerator = xs.GetEnumerator()
15+
while enumerator.MoveNext() do
16+
let first = enumerator.Current
17+
if enumerator.MoveNext() then
18+
let second = enumerator.Current
19+
yield first, second
20+
}
21+
1222
let evalPairwiseStrings a =
1323
match Seq.tryExactlyOne a with
1424
| Some "" -> None
15-
| _ -> a |> Seq.pairwise |> List.ofSeq |> Some
25+
| _ -> a |> pairs |> List.ofSeq |> Some
1626

1727
let evalPairwiseStringsNoOption a =
1828
evalPairwiseStrings a |> Option.defaultValue []
@@ -24,4 +34,4 @@ module Common =
2434
let waitForKey b =
2535
if b then
2636
printf "\nPress any key to continue ..."
27-
System.Console.ReadKey() |> ignore
37+
System.Console.ReadKey() |> ignore
Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,11 @@
1-
21
module FSharp.Formatting.CommandTool.Main
32

43
open CommandLine
54

6-
let printAssemblies msg =
7-
printfn "%s. Loaded Assemblies:" msg
8-
System.AppDomain.CurrentDomain.GetAssemblies()
9-
|> Seq.choose (fun a -> try Some (a.GetName().FullName, a.Location) with _ -> None)
10-
|> Seq.iter (fun (n, l) -> printfn "\t- %s: %s" n l)
11-
12-
135
[<EntryPoint>]
146
let main argv =
15-
try
16-
CommandLine.Parser.Default.ParseArguments(argv, typeof<BuildCommand>, typeof<WatchCommand>)
7+
CommandLine.Parser.Default.ParseArguments<BuildCommand, WatchCommand>(argv)
178
.MapResult(
189
(fun (opts: BuildCommand) -> opts.Execute()),
1910
(fun (opts: WatchCommand) -> opts.Execute()),
20-
(fun errs -> 1));
21-
with e ->
22-
let e =
23-
match e with
24-
| :? System.AggregateException as ex -> ex.InnerExceptions.[0]
25-
| _ -> e
26-
//printAssemblies "(DIAGNOSTICS) Documentation failed"
27-
printfn "fsdocs.exe failed: %O" e
28-
1
29-
//reraise()
11+
(fun _ -> 1))

0 commit comments

Comments
 (0)