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 23, 2023
1 parent 3a0f522 commit b6d8818
Show file tree
Hide file tree
Showing 2 changed files with 29 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
35 changes: 28 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,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 =
Expand All @@ -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()
Expand Down Expand Up @@ -901,14 +913,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 @@ -953,13 +968,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 b6d8818

Please sign in to comment.