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

Avoid printing extra new lines at the end of usage and refactor blank lines #592

Merged
merged 5 commits into from
Dec 1, 2024

Conversation

hogejo
Copy link
Contributor

@hogejo hogejo commented Nov 29, 2024

JCommander currently prints (in my examples) two extra empty lines at the end of usage. This makes the usage output look weird in my opinion.

One comes from a new line inserted by JCommander, which is not visible in tests, since those use the usage formatter directly.
Another one comes from commands, where the separating empty line was added regardless if there was another command coming.

I initially kept (but fixed) the command separating empty line, but I suggest removing all empty lines. Attached is a PR that removes all empty lines.

If you suggest keeping the empty line between commands, I suggest adding empty lines also after main line usage and options. I made the test code more verbose to see the new style. I also introduced one more test to compare the usage output from JCommander.usage() instead of the formatter.

@mkarg
Copy link
Collaborator

mkarg commented Nov 30, 2024

I think having blank lines between the commands helps the reader, particularly with long lists of options and commands.

@hogejo
Copy link
Contributor Author

hogejo commented Dec 1, 2024

Sure thing. How would you like this formatted then? My proposal is:

Usage: <main class> [options] [command] [command options]

  Options:
    -a, --a, --a-parameter
      a parameter
      Default: 0

  Commands:
    one      one command
      Usage: one [options]

        Options:
          -b, --b, --b-parameter
            b parameter
            Default: 0

    two      two command
      Usage: two [options]

        Options:
          -c, --c, --c-parameter
            c parameter
            Default: 0

Which adds a blank line before "Options", "Commands" as well us keeping the original blank line before commands (except the first one). This however means, that there is going to be a blank line before "Options" for commands as well.

The original looks like this:

Usage: <main class> [options] [command] [command options]
  Options:
    -a, --a, --a-parameter
      a parameter
      Default: 0
  Commands:
    one      one command
      Usage: one [options]
        Options:
          -b, --b, --b-parameter
            b parameter
            Default: 0

    two      two command
      Usage: two [options]
        Options:
          -c, --c, --c-parameter
            c parameter
            Default: 0

@mkarg
Copy link
Collaborator

mkarg commented Dec 1, 2024

Sure thing. How would you like this formatted then? My proposal is:

Usage: <main class> [options] [command] [command options]

  Options:
    -a, --a, --a-parameter
      a parameter
      Default: 0

  Commands:
    one      one command
      Usage: one [options]

        Options:
          -b, --b, --b-parameter
            b parameter
            Default: 0

    two      two command
      Usage: two [options]

        Options:
          -c, --c, --c-parameter
            c parameter
            Default: 0

Which adds a blank line before "Options", "Commands" as well us keeping the original blank line before commands (except the first one). This however means, that there is going to be a blank line before "Options" for commands as well.

LGTM! ❤️

@hogejo
Copy link
Contributor Author

hogejo commented Dec 1, 2024

Done. Please review and merge at your convenience @mkarg !

@hogejo hogejo changed the title Avoid printing extra new lines at the end of usage Avoid printing extra new lines at the end of usage and refactor blank lines Dec 1, 2024
@hogejo hogejo requested a review from mkarg December 1, 2024 13:47
@mkarg mkarg merged commit 81af743 into cbeust:master Dec 1, 2024
1 check passed
@hogejo hogejo deleted the remove-newlines-from-usage branch December 1, 2024 19:08
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

Successfully merging this pull request may close these issues.

2 participants