Add configurable automatic name mapping from camelCase
to kebab-case
#101
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #16
We maintain backwards compatibility by continuing to allow the
camelCase
names in addition to thekebab-case
names during argument parsing.When a an explicit
name = ???
is given to the@main
or@arg
annotation, that takes precedence over everything, and is not affected by the name mapping,Name mapping is configurable by passing in
nameMapper = mainargs.Util.snakeCaseNameMapper
ornameMapper = mainargs.Util.nullNameMapper
when you callParserForClass
orParserForMethods
I had to add a whole bunch of annoying shims to maintain binary compatibility when threading the new
nameMapper
through all our method signatures. That would be resolved by a proposal like https://contributors.scala-lang.org/t/can-we-make-adding-a-parameter-with-a-default-value-binary-compatible/6132/3, which alas does not exist yet in the Scala implementationThe duplication in method argument lists is getting very annoying. Again, this would be solved by a proposal like https://contributors.scala-lang.org/t/unpacking-classes-into-method-argument-lists/6329, which still doesn't exist in the language
Bumping to 0.6.0 since we cannot maintain bincompat for Scala 3 and Scala 2 simultaneously
case class
es that is compatible with both Scala 2 and Scala 3, due to differing method signature requirements. e.g.def unapply(x: MyCaseClass): Option[Tuple]
vsdef unapply(x: MyCaseClass): MyCaseClass
.Updated the docs and added coverage in the unit tests
I intend to release this as 0.5.5 once it lands