Make the project a positional argument

This commit is contained in:
Sven van Heugten 2026-04-27 23:23:20 +02:00
parent ce48b67d13
commit 91ab968154
No known key found for this signature in database
GPG key ID: D612F88666F4F660

View file

@ -25,7 +25,7 @@ type Command =
type Options = type Options =
{ Configuration: string { Configuration: string
ProjectPath: string option ProjectPath: string
BuildArgs: string list BuildArgs: string list
NoBuild: bool NoBuild: bool
Command: Command } Command: Command }
@ -79,19 +79,24 @@ let repoRoot =
stdout.Trim() stdout.Trim()
let parseArgs (args: string list) = let parseArgs (args: string list) =
let usage () =
fail "Usage: verify-coverage-mutants.fsx <path/to/project.fsproj> [--configuration Debug|Release] [--build-arg <value> ...] [--no-build] [--list | --show <id> | --run [id...]]"
let rec loop configuration projectPath buildArgs noBuild remaining = let rec loop configuration projectPath buildArgs noBuild remaining =
match remaining with match remaining with
| [] -> { Configuration = configuration; ProjectPath = projectPath; BuildArgs = List.rev buildArgs; NoBuild = noBuild; Command = Run [] } | [] -> { Configuration = configuration; ProjectPath = projectPath; BuildArgs = List.rev buildArgs; NoBuild = noBuild; Command = Run [] }
| "--configuration" :: value :: tail -> loop value projectPath buildArgs noBuild tail | "--configuration" :: value :: tail -> loop value projectPath buildArgs noBuild tail
| "--project" :: value :: tail -> loop configuration (Some value) buildArgs noBuild tail
| "--build-arg" :: value :: tail -> loop configuration projectPath (value :: buildArgs) noBuild tail | "--build-arg" :: value :: tail -> loop configuration projectPath (value :: buildArgs) noBuild tail
| "--no-build" :: tail -> loop configuration projectPath buildArgs true tail | "--no-build" :: tail -> loop configuration projectPath buildArgs true tail
| "--list" :: tail when tail.IsEmpty -> { Configuration = configuration; ProjectPath = projectPath; BuildArgs = List.rev buildArgs; NoBuild = noBuild; Command = List } | "--list" :: tail when tail.IsEmpty -> { Configuration = configuration; ProjectPath = projectPath; BuildArgs = List.rev buildArgs; NoBuild = noBuild; Command = List }
| "--show" :: id :: tail when tail.IsEmpty -> { Configuration = configuration; ProjectPath = projectPath; BuildArgs = List.rev buildArgs; NoBuild = noBuild; Command = Show id } | "--show" :: id :: tail when tail.IsEmpty -> { Configuration = configuration; ProjectPath = projectPath; BuildArgs = List.rev buildArgs; NoBuild = noBuild; Command = Show id }
| "--run" :: tail -> { Configuration = configuration; ProjectPath = projectPath; BuildArgs = List.rev buildArgs; NoBuild = noBuild; Command = Run tail } | "--run" :: tail -> { Configuration = configuration; ProjectPath = projectPath; BuildArgs = List.rev buildArgs; NoBuild = noBuild; Command = Run tail }
| value :: tail when not (value.StartsWith "--") -> { Configuration = configuration; ProjectPath = projectPath; BuildArgs = List.rev buildArgs; NoBuild = noBuild; Command = Run (value :: tail) } | value :: tail when not (value.StartsWith "--") -> { Configuration = configuration; ProjectPath = projectPath; BuildArgs = List.rev buildArgs; NoBuild = noBuild; Command = Run (value :: tail) }
| _ -> fail "Usage: dotnet fsi verify-coverage-mutants.fsx [--project <path/to/project.fsproj>] [--configuration Debug|Release] [--build-arg <value> ...] [--no-build] [--list | --show <id> | --run [id...]]" | _ -> usage ()
loop "Debug" None [] false args
match args with
| projectPath :: tail when not (projectPath.StartsWith "--") -> loop "Debug" projectPath [] false tail
| _ -> usage ()
let options = parseArgs (fsi.CommandLineArgs |> Array.skip 1 |> Array.toList) let options = parseArgs (fsi.CommandLineArgs |> Array.skip 1 |> Array.toList)
@ -114,9 +119,7 @@ let loadProjectInfo (projectPath: string) =
AbsoluteProjectPath = absoluteProjectPath } AbsoluteProjectPath = absoluteProjectPath }
let project = let project =
match options.ProjectPath with loadProjectInfo options.ProjectPath
| Some projectPath -> loadProjectInfo projectPath
| None -> fail "Missing required --project <path/to/project.fsproj>."
let targetPathForProject (workingDirectory: string) (projectPath: string) = let targetPathForProject (workingDirectory: string) (projectPath: string) =
let exitCode, stdout, stderr = let exitCode, stdout, stderr =