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