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

Using argument nameMapper in function runOrExit does not compile #154

Closed
jk-1 opened this issue Sep 4, 2024 · 6 comments
Closed

Using argument nameMapper in function runOrExit does not compile #154

jk-1 opened this issue Sep 4, 2024 · 6 comments

Comments

@jk-1
Copy link

jk-1 commented Sep 4, 2024

Mainargs docs Customization says:

nameMapper: String => Option[String]: how Scala camelCase names are mapping to CLI command and flag names. Defaults to translation to kebab-case, but you can pass in mainargs.Util.snakeCaseNameMapper for snake_case CLI names or mainargs.Util.nullNameMapper to disable mapping.

I tried this code:

def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args, allowPositional = true, nameMapper = mainargs.Util.snakeCaseNameMapper)
and got the error:

scala-cli MyTool.scala -- --help
Compiling project (Scala 2.13.14, JVM (17))
[error] ./MyTool.scala:948:104
[error] unknown parameter name: nameMapper
[error]   def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args, allowPositional = true, nameMapper = mainargs.Util.snakeCaseNameMapper)
[error]                                                                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error compiling project (Scala 2.13.14, JVM (17))
Compilation failed

Mainargs code is

def runOrExit(
      args: Seq[String],
      allowPositional: Boolean = false,
      allowRepeats: Boolean = false,
      stderr: PrintStream = System.err,
      totalWidth: Int = 100,
      printHelpOnExit: Boolean = true,
      docsOnNewLine: Boolean = false,
      autoPrintHelpAndExit: Option[(Int, PrintStream)] = Some((0, System.out)),
      customNames: Map[String, String] = Map(),
      customDocs: Map[String, String] = Map()
  ): Any

So there is no nameMapper.

Is this error in mainargs code/docs or do I use it somehow incorrectly?

Used mainargs v is 0.7.2

@lihaoyi
Copy link
Member

lihaoyi commented Sep 4, 2024

Looks like we added it to all the runOr* methods except forgetting about runOrExit

@lihaoyi
Copy link
Member

lihaoyi commented Sep 4, 2024

#155

@jk-1
Copy link
Author

jk-1 commented Sep 4, 2024

https://github.com/com-lihaoyi/mainargs/blob/main/mainargs/src/Parser.scala

I found it only in runRaw, no other run* funcs.

@lihaoyi
Copy link
Member

lihaoyi commented Sep 4, 2024

@lihaoyi
Copy link
Member

lihaoyi commented Sep 4, 2024

@lihaoyi
Copy link
Member

lihaoyi commented Sep 4, 2024

Should be fixed in 0.7.3 which is on its way to Maven Central

@lihaoyi lihaoyi closed this as completed Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants