From b6d88185ec87d613428624d4d9fae631a35060c7 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Wed, 23 Aug 2023 23:44:30 +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 that case the script launcher.sh is used instead of the 'fsx' proj. [1] https://github.com/nblockchain/fsx/issues/34 --- fsx/Program.fs | 2 +- fsxc/Fsxc.fs | 35 ++++++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/fsx/Program.fs b/fsx/Program.fs index 5460b57..486f580 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 da4f7f0..3b63e93 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,7 +60,12 @@ module Program = tmpNuget) #endif - let PrintUsage() = + let PrintUsage(invocationType: ProgramInvocationType) = + let programInvocation = + match invocationType with + | FsxcPureInvocation -> "fsxc" + | FsxLauncherScript -> "fsx" + Console.WriteLine() let dotnetToolPrefix = @@ -67,7 +76,10 @@ module Program = #endif Console.WriteLine( - sprintf "Usage: %sfsxc [OPTION] yourscript.fsx" dotnetToolPrefix + sprintf + "Usage: %s%s [OPTION] yourScript.fsx" + dotnetToolPrefix + programInvocation ) Console.WriteLine() @@ -901,14 +913,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 = @@ -953,9 +968,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 @@ -963,3 +978,9 @@ let fsi = { CommandLineArgs = System.Environment.GetCommandLineArgs() } #else () #endif + + let internal Main argv = + WrapperForMain ProgramInvocationType.FsxcPureInvocation argv + + let OuterMain argv = + WrapperForMain ProgramInvocationType.FsxLauncherScript argv