Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ArgumentParser): Correct default programName when run via wrapper #233

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:/fsprojects/Argu/pull/233)

### 6.2.1
* Fix `ParseResults.ProgramName` - make it public (cut and paste error in [#229](https:/fsprojects/Argu/pull/229)) [#231](https:/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