-
Notifications
You must be signed in to change notification settings - Fork 324
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
Add new shouldUseExecutableName
configuration property (Issue #295)
#501
base: main
Are you sure you want to change the base?
Conversation
This adds the `shouldUseExecutableName` property, allowing the command name to be derived from the executable's file name. The property defaults to false, both because subcommands using it is probably undesirable and to preserve existing behaviour after updating the package.
shouldUseExecutableName
configuration propertyshouldUseExecutableName
configuration property (Issue #295)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR, @QuaqSim!
The interaction with commandName
and _superCommandName
is definitely tricky. I'm not 100% sure that ignoring the new property when commandName
is non-nil
is always the right call. In particular, I think during development that could lead to an unexpected display (since the executable there takes on the target name, which may not be the same as the intended name after installing). I think you're right that _superCommandName
being set should override everything else.
If you were designing this configuration from scratch, without any worry about source compatibility, how would you design it?
Sources/ArgumentParser/Parsable Types/CommandConfiguration.swift
Outdated
Show resolved
Hide resolved
If I'm interpreting this correctly, you're suggesting that if For example, if the target name and If we agree that
Without worrying about source compatibility, I would use a CommandName enumeration in order to clearly assign exactly one selection. Something like... public enum CommandName {
case snakeCasedTypeName
case executableName
case explicit(String)
}
public struct CommandConfiguration {
public var commandName: CommandName
...
public init(
commandName: CommandName = .snakeCasedTypeName
... I'm not sure how indirect case niceDescriptiveNameImFailingToThinkOf((superCommandName: String, commandName: CommandName)) Only |
This doesn't change test behaviour in any way. Single quotes were escaped unnecessarily for some tests, these escapes have been removed to make them consistent and clearer.
Do you have any feedback on how you would like me to proceed with this? I think the |
Foundation imports were reduced to only the necessary protocols or types in the main branch. After merging, we need to import `Foundation.URL` for use in `executableName`.
Oop, I shoulda looked at the open PRs before hacking on #641 😅. I went with making it the default and foregoing a new config option, but this seems more sane from a back compat standpoint. |
Description
This adds the
shouldUseExecutableName
property toCommandConfiguration
, allowing the command name to be derived from the executable's file name.The property defaults to false, both because subcommands using it is probably undesirable and to preserve existing behaviour after updating the package.
This also adds
/DerivedData
to the git ignore list.Detailed Design
The
CommandConfiguration
initialisers use a default value of false, serving to allow existing code to compile and to avoid an unexpected change in behaviour. When the value is true, if bothcommandName
and_superCommandName
are nil, the command name will be derived from the first command line argument, i.e. the path to the running executable.Change to associated code paths is minimal, specifically
ParsableCommand._commandName
has been expanded in a way that preserves the original outcome when the new property is false.The thinking behind ignoring this value when either
commandName
or_superCommandName
have been set is that if the command name has been explicitly set, this should be used. If the super command name has been set, this implies a relationship with another command where a dynamic command name may lead to inconsistent help texts.Two new internal symbols - see diff for full API documentation.
Documentation Plan
Includes API documentation for the new symbols and minorly updates docs to expose the new property.
Test Plan
Includes unit tests for the string quoting. I'm unaware of a guaranteed executable name when running tests and therefore this does not include tests for the command name generation.
Source Impact
Existing users should not be impacted by this change.
Checklist