Skip to content

Commit 33c67be

Browse files
authored
Add missing nameMapper flag to .runOrExit (#155)
Also fix `runOrEither`s `sort` flag to make it default to `true` as the doxs suggest it should
1 parent e1ffb36 commit 33c67be

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

mainargs/src/Parser.scala

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ class ParserForMethods[B](val mains: MethodMains[B]) {
5454
docsOnNewLine: Boolean = false,
5555
autoPrintHelpAndExit: Option[(Int, PrintStream)] = Some((0, System.out)),
5656
customNames: Map[String, String] = Map(),
57-
customDocs: Map[String, String] = Map()
57+
customDocs: Map[String, String] = Map(),
58+
sorted: Boolean = true,
59+
nameMapper: String => Option[String] = Util.kebabCaseNameMapper
5860
): Any = {
5961
runEither(
6062
args,
@@ -65,7 +67,9 @@ class ParserForMethods[B](val mains: MethodMains[B]) {
6567
docsOnNewLine,
6668
autoPrintHelpAndExit,
6769
customNames,
68-
customDocs
70+
customDocs,
71+
sorted,
72+
nameMapper
6973
) match {
7074
case Left(msg) =>
7175
stderr.println(msg)
@@ -74,6 +78,32 @@ class ParserForMethods[B](val mains: MethodMains[B]) {
7478
}
7579
}
7680

81+
def runOrExit(
82+
args: Seq[String],
83+
allowPositional: Boolean,
84+
allowRepeats: Boolean,
85+
stderr: PrintStream,
86+
totalWidth: Int,
87+
printHelpOnExit: Boolean,
88+
docsOnNewLine: Boolean,
89+
autoPrintHelpAndExit: Option[(Int, PrintStream)],
90+
customNames: Map[String, String],
91+
customDocs: Map[String, String]
92+
): Any = {
93+
runOrExit(
94+
args,
95+
allowPositional,
96+
allowRepeats,
97+
stderr,
98+
totalWidth,
99+
printHelpOnExit,
100+
docsOnNewLine,
101+
autoPrintHelpAndExit,
102+
customNames,
103+
customDocs,
104+
)
105+
}
106+
77107
def runOrThrow(
78108
args: Seq[String],
79109
allowPositional: Boolean,
@@ -135,7 +165,7 @@ class ParserForMethods[B](val mains: MethodMains[B]) {
135165
autoPrintHelpAndExit: Option[(Int, PrintStream)] = Some((0, System.out)),
136166
customNames: Map[String, String] = Map(),
137167
customDocs: Map[String, String] = Map(),
138-
sorted: Boolean = false,
168+
sorted: Boolean = true,
139169
nameMapper: String => Option[String] = Util.kebabCaseNameMapper
140170
): Either[String, Any] = {
141171
if (autoPrintHelpAndExit.nonEmpty && args.take(1) == Seq("--help")) {

mainargs/test/src/EqualsSyntaxTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ object EqualsSyntaxTests extends TestSuite {
4242
ParserForMethods(Main).runEither(Array("--foo=bar", "--bool=true")) ==>
4343
Left("""Unknown argument: "--bool=true"
4444
|Expected Signature: run
45+
| --bool Example flag
4546
| -f --foo <str> String to print repeatedly
4647
| --my-num <int> How many times to print string
47-
| --bool Example flag
4848
|
4949
|""".stripMargin)
5050
}

0 commit comments

Comments
 (0)