From 750159c6c5dffe057e12776f0fc190436c491f50 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Mon, 21 Aug 2023 14:03:37 +0800 Subject: [PATCH] fsx,fsxc: fix PrintUsage() to identify program 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 Linux and macOS we still use launcher.sh instead of fsx proj. [1] https://github.com/nblockchain/fsx/issues/34 --- fsx/Program.fs | 2 +- fsxc/Fsxc.fs | 36 +++++++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/fsx/Program.fs b/fsx/Program.fs index 978b4b19..754a74a6 100644 --- a/fsx/Program.fs +++ b/fsx/Program.fs @@ -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 -> diff --git a/fsxc/Fsxc.fs b/fsxc/Fsxc.fs index e09383fc..e78abd6f 100644 --- a/fsxc/Fsxc.fs +++ b/fsxc/Fsxc.fs @@ -40,6 +40,10 @@ type BuildResult = | Failure of BinFolder | Success of ExeTarget +type ProgramInvocationType = + | FsxLauncherScript + | FsxcPureInvocation + exception NoScriptProvided module Program = @@ -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" @@ -890,14 +903,17 @@ let fsi = { CommandLineArgs = System.Environment.GetCommandLineArgs() } exeTarget.Exe - let private InnerMain(argv: array) = + let private InnerMain + (invocationType: ProgramInvocationType) + (argv: array) + = 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 = @@ -942,9 +958,9 @@ 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 @@ -952,3 +968,9 @@ let fsi = { CommandLineArgs = System.Environment.GetCommandLineArgs() } #else () #endif + + let internal Main argv = + WrapperForMain ProgramInvocationType.FsxcPureInvocation argv + + let OuterMain argv = + WrapperForMain ProgramInvocationType.FsxLauncherScript argv