Skip to content

Commit

Permalink
fix(ArgumentParser): Correct programName when run via wrapper EXE (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink authored Feb 28, 2024
1 parent 40e0e26 commit 5fb339f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 6.2.2
* Fix default `programName` when invoking via a wrapper such as `dotnet.exe` [#233](https://github.com/fsprojects/Argu/pull/233)

### 6.2.1
* Fix `ParseResults.ProgramName` - make it public (cut and paste error in [#229](https://github.com/fsprojects/Argu/pull/229)) [#231](https://github.com/fsprojects/Argu/pull/231)

Expand Down
2 changes: 1 addition & 1 deletion src/Argu/ArgumentParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ and [<Sealed; NoEquality; NoComparison; AutoSerializable(false)>]
/// <summary>
/// Creates a new parser instance based on supplied F# union template.
/// </summary>
/// <param name="programName">Program identifier, e.g. 'cat'. Defaults to the current executable name.</param>
/// <param name="programName">Program identifier, e.g. 'cat'. Defaults to the current running executable per <c>Assembly.GetEntryAssembly()</c>.</param>
/// <param name="helpTextMessage">Message that will be displayed at the top of the help text.</param>
/// <param name="usageStringCharacterWidth">Text width used when formatting the usage string. Defaults to 80 chars.</param>
/// <param name="errorHandler">The implementation of IExiter used for error handling. Exception is default.</param>
Expand Down
7 changes: 5 additions & 2 deletions src/Argu/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ type IDictionary<'K,'V> with
if ok then Some found
else None

let currentProgramName = lazy System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName
// NOTE: Prior to 6.2.2, this was System.Diagnostics.Process.GetCurrentProcess()
// That previous approach derives `dotnet` when you `dotnet run` a program
// (or you invoke via `dotnet tool run` and/or if your IDE wraps the invocation etc)
let currentProgramName = lazy Assembly.GetEntryAssembly().GetName().Name

/// recognize exprs that strictly contain DU constructors
/// e.g. <@ Case @> is valid but <@ fun x y -> Case y x @> is invalid
Expand Down Expand Up @@ -353,4 +356,4 @@ let wordwrap (width:int) (inputText:string) =

pos <- next

lines.ToArray() |> Array.toList
lines.ToArray() |> Array.toList

0 comments on commit 5fb339f

Please sign in to comment.