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

hiding variable names should be default in help output #1984

Closed
kenyee opened this issue Mar 27, 2023 · 6 comments
Closed

hiding variable names should be default in help output #1984

kenyee opened this issue Mar 27, 2023 · 6 comments
Labels
lang: kotlin Kotlin-related theme: usagehelp An issue or change related to the usage help message type: enhancement ✨
Milestone

Comments

@kenyee
Copy link

kenyee commented Mar 27, 2023

Hiding the variable names as described here:
https://stackoverflow.com/questions/65130421/picocli-cli-parser-hide-the-java-variable-name-while-rendering-the-output

should be the default behavior IMHO. I can't see why anyone would want the current default behavior...
e.g., if you use a parser for the option, it prints this out:

  -d, --baseDirectory=<baseDirectory$parser>

Not sure why you'd ever want to show the $parser bit unless you're in some sort of parser debug mode...

@kenyee kenyee changed the title hiding variable names should be default hiding variable names should be default in help output Mar 27, 2023
@remkop
Copy link
Owner

remkop commented Mar 27, 2023

Interesting question.

How did you get that variable name baseDirectory$parser? That's an unusual variable name!

Also, please be aware, you can customize unhelpful variable names with the paramLabel annotation attribute.

Most CLI tools that I am aware of do display a parameter label for options that take a parameter.
This communicates to users that the option takes a parameter (as opposed to boolean flags) and gives a hint as to what kind of information the user should provide (a number, a String, a URL, file name, directory, etc).

Some examples: ping, ls and git.

So, I am curious why you believe that hiding the option parameter label should be the default.

@kenyee
Copy link
Author

kenyee commented Apr 1, 2023

How did you get that variable name baseDirectory$parser? That's an unusual variable name!

    @CommandLine.Option(
        names = ["-d", "--baseDirectory"],
        required = true,
        description = ["Base directory from the repo (useful for mono-repos)"],
        defaultValue = ".",
        showDefaultValue = CommandLine.Help.Visibility.ALWAYS,
        scope = CommandLine.ScopeType.INHERIT,
    )
    internal fun setBaseDirectory(dir: String) {
        baseDirectory = dir
    }

Thanks...paramLabel would cover what I'd want to do (mainly to hide that ugly variable name) :-)
Might be worth hiding the variable name if it's a method?

@remkop
Copy link
Owner

remkop commented Apr 1, 2023

Oh interesting!
Picocli takes the @Option-annotated method name and uses its "property name" (remove leading get or set and decapitalize the remainder) as the auto-generated parameter label.

Still, in the example you provided, that should result in picocli generating the label baseDirectory, so I still wonder where the $parser bit comes from...

Unless the method name setBaseDirectory$parser is somehow generated by Kotlin? Hm, curious.

Glad to hear that explicitly specifying the paramLabel string solves the issue for you.

@kenyee
Copy link
Author

kenyee commented Apr 1, 2023

Yep, it's a kotlin'ism....which is why the default didn't work 🙂

@remkop
Copy link
Owner

remkop commented Apr 2, 2023

Okay, I did some reading and it seems that Kotlin does "name mangling" for internal members so they cannot easily be called from Java. Apparently that is implemented by appending $<SOMESTUFF> to the method name.

I will look at truncating the $ and everything following it from the method name when inferring paramLabel from method names.

@remkop remkop added this to the 4.7.2 milestone Apr 2, 2023
@remkop remkop added lang: kotlin Kotlin-related type: enhancement ✨ theme: usagehelp An issue or change related to the usage help message labels Apr 2, 2023
remkop added a commit that referenced this issue Apr 2, 2023
Kotlin `internal` methods have mangled names with embedded "$"; truncate this portion off the paramLabel
@remkop
Copy link
Owner

remkop commented Apr 2, 2023

@kenyee

I pushed a fix for this, and from the next version of picocli (4.7.2), the $ and everything following it will be removed from the automatically generated paramLabel for annotated methods.

Thank you again for raising this.

@remkop remkop closed this as completed Apr 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang: kotlin Kotlin-related theme: usagehelp An issue or change related to the usage help message type: enhancement ✨
Projects
None yet
Development

No branches or pull requests

2 participants