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

Add missing nameMapper flag to .runOrExit #155

Merged
merged 2 commits into from
Sep 4, 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
36 changes: 33 additions & 3 deletions mainargs/src/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ class ParserForMethods[B](val mains: MethodMains[B]) {
docsOnNewLine: Boolean = false,
autoPrintHelpAndExit: Option[(Int, PrintStream)] = Some((0, System.out)),
customNames: Map[String, String] = Map(),
customDocs: Map[String, String] = Map()
customDocs: Map[String, String] = Map(),
sorted: Boolean = true,
nameMapper: String => Option[String] = Util.kebabCaseNameMapper
): Any = {
runEither(
args,
Expand All @@ -65,7 +67,9 @@ class ParserForMethods[B](val mains: MethodMains[B]) {
docsOnNewLine,
autoPrintHelpAndExit,
customNames,
customDocs
customDocs,
sorted,
nameMapper
) match {
case Left(msg) =>
stderr.println(msg)
Expand All @@ -74,6 +78,32 @@ class ParserForMethods[B](val mains: MethodMains[B]) {
}
}

def runOrExit(
args: Seq[String],
allowPositional: Boolean,
allowRepeats: Boolean,
stderr: PrintStream,
totalWidth: Int,
printHelpOnExit: Boolean,
docsOnNewLine: Boolean,
autoPrintHelpAndExit: Option[(Int, PrintStream)],
customNames: Map[String, String],
customDocs: Map[String, String]
): Any = {
runOrExit(
args,
allowPositional,
allowRepeats,
stderr,
totalWidth,
printHelpOnExit,
docsOnNewLine,
autoPrintHelpAndExit,
customNames,
customDocs,
)
}

def runOrThrow(
args: Seq[String],
allowPositional: Boolean,
Expand Down Expand Up @@ -135,7 +165,7 @@ class ParserForMethods[B](val mains: MethodMains[B]) {
autoPrintHelpAndExit: Option[(Int, PrintStream)] = Some((0, System.out)),
customNames: Map[String, String] = Map(),
customDocs: Map[String, String] = Map(),
sorted: Boolean = false,
sorted: Boolean = true,
nameMapper: String => Option[String] = Util.kebabCaseNameMapper
): Either[String, Any] = {
if (autoPrintHelpAndExit.nonEmpty && args.take(1) == Seq("--help")) {
Expand Down
2 changes: 1 addition & 1 deletion mainargs/test/src/EqualsSyntaxTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ object EqualsSyntaxTests extends TestSuite {
ParserForMethods(Main).runEither(Array("--foo=bar", "--bool=true")) ==>
Left("""Unknown argument: "--bool=true"
|Expected Signature: run
| --bool Example flag
| -f --foo <str> String to print repeatedly
| --my-num <int> How many times to print string
| --bool Example flag
|
|""".stripMargin)
}
Expand Down