Skip to content

Commit

Permalink
fsx,fsxc: fix PrintUsage() to identify program
Browse files Browse the repository at this point in the history
Partially addresses this bug[1], but only partially because it
still happens in Unix (when not installed via `dotnet
tool install`), due to the fact that in that case the script
launcher.sh is used instead of the 'fsx' proj.

[1] #34
  • Loading branch information
knocte committed Aug 21, 2023
1 parent 304fc20 commit dc62d8c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion fsx/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ let fsxcMainArguments =
Seq.append fsxcArgs (Seq.singleton userScriptPath) |> Seq.toArray
| None -> fsxcArgs |> Seq.toArray

Program.Main fsxcMainArguments |> ignore
Program.OuterMain fsxcMainArguments |> ignore

match maybeUserScriptPath with
| None ->
Expand Down
36 changes: 29 additions & 7 deletions fsxc/Fsxc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ type BuildResult =
| Failure of BinFolder
| Success of ExeTarget

type ProgramInvocationType =
| FsxLauncherScript
| FsxcPureInvocation

exception NoScriptProvided

module Program =
Expand All @@ -56,9 +60,18 @@ module Program =
tmpNuget)
#endif

let PrintUsage() =
let PrintUsage(invocationType: ProgramInvocationType) =
let programInvocation =
match invocationType with
| FsxcPureInvocation -> "dotnet fsxc"
| FsxLauncherScript -> "fsx"

Console.WriteLine()
Console.WriteLine "Usage: dotnet fsxc [OPTION] yourscript.fsx"

Console.WriteLine(
sprintf "Usage: %s [OPTION] yourscript.fsx" programInvocation
)

Console.WriteLine()
Console.WriteLine "Options"

Expand Down Expand Up @@ -890,14 +903,17 @@ let fsi = { CommandLineArgs = System.Environment.GetCommandLineArgs() }

exeTarget.Exe

let private InnerMain(argv: array<string>) =
let private InnerMain
(invocationType: ProgramInvocationType)
(argv: array<string>)
=
if argv.Length = 0 then
Console.Error.WriteLine "Please pass the .fsx script as an argument"
PrintUsage()
PrintUsage invocationType
Environment.Exit 1

if argv.Length = 1 && argv.[0] = "--help" then
PrintUsage()
PrintUsage invocationType
Environment.Exit 0

let parsedArgs =
Expand Down Expand Up @@ -942,13 +958,19 @@ let fsi = { CommandLineArgs = System.Environment.GetCommandLineArgs() }

0 // return an integer exit code

let Main argv =
let private WrapperForMain invocationType argv =
try
InnerMain argv
InnerMain invocationType argv
finally
#if LEGACY_FRAMEWORK
if nugetExeTmpLocation.IsValueCreated then
nugetExeTmpLocation.Value.Delete()
#else
()
#endif

let internal Main argv =
WrapperForMain ProgramInvocationType.FsxcPureInvocation argv

let OuterMain argv =
WrapperForMain ProgramInvocationType.FsxLauncherScript argv

0 comments on commit dc62d8c

Please sign in to comment.