Skip to content

Commit

Permalink
Refactor the project cracker into a new file et al. (#618)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
teo-tsirpanis authored Oct 24, 2020
1 parent 60cb2cf commit f523d4c
Show file tree
Hide file tree
Showing 11 changed files with 649 additions and 937 deletions.
4 changes: 2 additions & 2 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"isRoot": true,
"tools": {
"fake-cli": {
"version": "5.20.0",
"version": "5.20.3",
"commands": [
"fake"
]
},
"paket": {
"version": "5.245.2",
"version": "5.249.0",
"commands": [
"paket"
]
Expand Down
4 changes: 2 additions & 2 deletions paket.dependencies
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version 5.247.4
version 5.249.0
source https://api.nuget.org/v3/index.json
framework: auto-detect
storage: none
Expand All @@ -9,7 +9,7 @@ nuget CommandLineParser ~> 2.8
nuget Dotnet.ProjInfo
nuget Dotnet.ProjInfo.Workspace
nuget Newtonsoft.Json
nuget Suave 2.1.1
nuget Suave
nuget System.Memory

# Used to create notebook docs with mybinder links that work
Expand Down
659 changes: 190 additions & 469 deletions paket.lock

Large diffs are not rendered by default.

451 changes: 18 additions & 433 deletions src/FSharp.Formatting.CommandTool/BuildCommand.fs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<Link>Common\AssemblyInfo.fs</Link>
</Compile>
<Compile Include="Options.fs" />
<Compile Include="ProjectCracker.fs" />
<Compile Include="BuildCommand.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
Expand Down
14 changes: 12 additions & 2 deletions src/FSharp.Formatting.CommandTool/Options.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,20 @@ module Common =
| Some "" -> None
| _ -> Some (List.ofSeq a)

// https://stackoverflow.com/questions/4126351
let private pairs (xs: _ seq) = seq {
use enumerator = xs.GetEnumerator()
while enumerator.MoveNext() do
let first = enumerator.Current
if enumerator.MoveNext() then
let second = enumerator.Current
yield first, second
}

let evalPairwiseStrings a =
match Seq.tryExactlyOne a with
| Some "" -> None
| _ -> a |> Seq.pairwise |> List.ofSeq |> Some
| _ -> a |> pairs |> List.ofSeq |> Some

let evalPairwiseStringsNoOption a =
evalPairwiseStrings a |> Option.defaultValue []
Expand All @@ -24,4 +34,4 @@ module Common =
let waitForKey b =
if b then
printf "\nPress any key to continue ..."
System.Console.ReadKey() |> ignore
System.Console.ReadKey() |> ignore
22 changes: 2 additions & 20 deletions src/FSharp.Formatting.CommandTool/Program.fs
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@

module FSharp.Formatting.CommandTool.Main

open CommandLine

let printAssemblies msg =
printfn "%s. Loaded Assemblies:" msg
System.AppDomain.CurrentDomain.GetAssemblies()
|> Seq.choose (fun a -> try Some (a.GetName().FullName, a.Location) with _ -> None)
|> Seq.iter (fun (n, l) -> printfn "\t- %s: %s" n l)


[<EntryPoint>]
let main argv =
try
CommandLine.Parser.Default.ParseArguments(argv, typeof<BuildCommand>, typeof<WatchCommand>)
CommandLine.Parser.Default.ParseArguments<BuildCommand, WatchCommand>(argv)
.MapResult(
(fun (opts: BuildCommand) -> opts.Execute()),
(fun (opts: WatchCommand) -> opts.Execute()),
(fun errs -> 1));
with e ->
let e =
match e with
| :? System.AggregateException as ex -> ex.InnerExceptions.[0]
| _ -> e
//printAssemblies "(DIAGNOSTICS) Documentation failed"
printfn "fsdocs.exe failed: %O" e
1
//reraise()
(fun _ -> 1))
Loading

0 comments on commit f523d4c

Please sign in to comment.