Skip to content

Commit 5fb339f

Browse files
authored
fix(ArgumentParser): Correct programName when run via wrapper EXE (#233)
1 parent 40e0e26 commit 5fb339f

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

RELEASE_NOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### 6.2.2
2+
* Fix default `programName` when invoking via a wrapper such as `dotnet.exe` [#233](https://github.com/fsprojects/Argu/pull/233)
3+
14
### 6.2.1
25
* 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)
36

src/Argu/ArgumentParser.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ and [<Sealed; NoEquality; NoComparison; AutoSerializable(false)>]
9999
/// <summary>
100100
/// Creates a new parser instance based on supplied F# union template.
101101
/// </summary>
102-
/// <param name="programName">Program identifier, e.g. 'cat'. Defaults to the current executable name.</param>
102+
/// <param name="programName">Program identifier, e.g. 'cat'. Defaults to the current running executable per <c>Assembly.GetEntryAssembly()</c>.</param>
103103
/// <param name="helpTextMessage">Message that will be displayed at the top of the help text.</param>
104104
/// <param name="usageStringCharacterWidth">Text width used when formatting the usage string. Defaults to 80 chars.</param>
105105
/// <param name="errorHandler">The implementation of IExiter used for error handling. Exception is default.</param>

src/Argu/Utils.fs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ type IDictionary<'K,'V> with
135135
if ok then Some found
136136
else None
137137

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

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

354357
pos <- next
355358

356-
lines.ToArray() |> Array.toList
359+
lines.ToArray() |> Array.toList

0 commit comments

Comments
 (0)