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

Excludes hidden options, params, and subcommands from man page generation #1064

Merged
merged 6 commits into from
May 28, 2020

Conversation

bdemers
Copy link
Contributor

@bdemers bdemers commented May 21, 2020

Fixes: #1063

@@ -6693,6 +6705,7 @@ void initDefaultValueProvider(Class<? extends IDefaultValueProvider> value, IFac
void updateHelpCommand(boolean value) { if (isNonDefault(value, DEFAULT_IS_HELP_COMMAND)) {isHelpCommand = value;} }
void updateSubcommandsRepeatable(boolean value) { if (isNonDefault(value, DEFAULT_SUBCOMMANDS_REPEATABLE)) {subcommandsRepeatable = value;} }
void updateAddMethodSubcommands(boolean value) { if (isNonDefault(value, DEFAULT_IS_ADD_METHOD_SUBCOMMANDS)) {isAddMethodSubcommands = value;} }
void updateHidden(boolean value) { if (isNonDefault(value, DEFAULT_HIDDEN)) { isHidden = value; } }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@remkop I didn't see another way of access the hidden prop, but I'm probably missing something as it is used for the help text output.
If you have any alternative idea let me know, and I could remove this method (and revert the MINOR version bump)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bdemers The @Command(hidden) value is captured as a property of the command's UsageHelpMessageSpec. I admit this is not easy to find. Perhaps the javadoc for picocli.CommandLine.Command#hidden should have a @see picocli.CommandLine.Model.UsageMessageSpec#hidden() reference to make this a bit easier to find. Can you do that as part of the PR?

The Help class has its own map of subcommands, and when this map is built up in CommandLine.Help#addAllSubcommands, hidden subcommands are excluded. This means that the logic for Help is simpler, because it does not need to care about hidden subcommands any more, but can be a bit puzzling if you miss this. This should be mentioned in the javadoc for Help#addAllSubcommands and the javadoc for Help#subcommands. Can you include that in the PR?

Good finds, thanks! 👍

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we can use picocli.CommandLine.Model.UsageMessageSpec#hidden, all changes to CommandLine can be reverted.

@codecov-commenter
Copy link

codecov-commenter commented May 21, 2020

Codecov Report

Merging #1064 into master will increase coverage by 0.10%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1064      +/-   ##
============================================
+ Coverage     94.35%   94.46%   +0.10%     
- Complexity      442      448       +6     
============================================
  Files             2        2              
  Lines          6484     6571      +87     
  Branches       1736     1765      +29     
============================================
+ Hits           6118     6207      +89     
+ Misses           94       93       -1     
+ Partials        272      271       -1     
Impacted Files Coverage Δ Complexity Δ
src/main/java/picocli/AutoComplete.java 96.98% <0.00%> (-0.06%) 139.00% <0.00%> (ø%)
src/main/java/picocli/CommandLine.java 94.31% <0.00%> (+0.12%) 309.00% <0.00%> (+6.00%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d1b9a30...2c96e69. Read the comment docs.

Copy link
Owner

@remkop remkop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall good progress! Thanks for taking care of this!
I added some more comments.

@@ -16,7 +16,7 @@ springBootVersion = 2.2.2.RELEASE
projectPreviousReleaseVersion = 4\\.3\\.2
# projectPreviousVersionRegex may be a SNAPSHOT
projectPreviousVersionRegex = 4\\.3\\.2
projectVersion = 4.3.3-SNAPSHOT
projectVersion = 4.4.0-SNAPSHOT
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be reverted.

@@ -193,7 +193,7 @@ static int generateManPage(Config config, CommandSpec... specs) throws IOExcepti
// recursively create man pages for subcommands
for (CommandLine sub : spec.subcommands().values()) {
CommandSpec subSpec = sub.getCommandSpec();
if (done.contains(subSpec)) {continue;}
if (done.contains(subSpec) || subSpec.hidden()) {continue;}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use picocli.CommandLine.Model.UsageMessageSpec#hidden here.

pw.printf(" %s%n", rows[0][4]);
for (int i = 1; i < rows.length; i++) {
pw.printf("+%n%s%n", rows[i][4]);
if (!positional.hidden()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a similar if statement in writeOption : if (!option.hidden()) ...,
or should we exclude hidden PositionalParamSpec before the writePositional method is called?
I would like it if we can do this in a consistent manner for options, positionals and commands.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, keeping the check in writeOption/writePositional is easier, as writePositional is called from multiple places.

However, the check for the subcommands gets a little trickier, the subcommands need to be removed before processing to avoid the tag/"Commands" heading.

Thoughts?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After thinking about this some more, I think your original approach to filter out hidden args first is better.

The reason is the same as for subcommands: if all options or positional parameters are hidden, we don't want to include the tag and heading in the output. (see also #1071)

@@ -6693,6 +6705,7 @@ void initDefaultValueProvider(Class<? extends IDefaultValueProvider> value, IFac
void updateHelpCommand(boolean value) { if (isNonDefault(value, DEFAULT_IS_HELP_COMMAND)) {isHelpCommand = value;} }
void updateSubcommandsRepeatable(boolean value) { if (isNonDefault(value, DEFAULT_SUBCOMMANDS_REPEATABLE)) {subcommandsRepeatable = value;} }
void updateAddMethodSubcommands(boolean value) { if (isNonDefault(value, DEFAULT_IS_ADD_METHOD_SUBCOMMANDS)) {isAddMethodSubcommands = value;} }
void updateHidden(boolean value) { if (isNonDefault(value, DEFAULT_HIDDEN)) { isHidden = value; } }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we can use picocli.CommandLine.Model.UsageMessageSpec#hidden, all changes to CommandLine can be reverted.

@remkop remkop added this to the 4.4 milestone May 21, 2020
@remkop remkop added the theme: codegen An issue or change related to the picocli-codegen module label May 21, 2020
@remkop
Copy link
Owner

remkop commented May 26, 2020

FYI: This issue may be relevant: #1071

@bdemers
Copy link
Contributor Author

bdemers commented May 26, 2020

Still one more comment to address, but I reverted the new method and version bump

@remkop
Copy link
Owner

remkop commented May 26, 2020

Thanks for the updates! Please let me know when this is ready for review.

@bdemers
Copy link
Contributor Author

bdemers commented May 27, 2020

Hey @remkop it's ready. though I did have a question/comment: https://github.com/remkop/picocli/pull/1064/files#r430546512

Copy link
Owner

@remkop remkop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replied to your comment, but #1071 made clear that your original approach is better:
Filter out hidden args first allows us to avoid emitting a header without any content in the man page.

@bdemers
Copy link
Contributor Author

bdemers commented May 27, 2020

@remkop good call, I updated the test to make sure the Arguments header is not included when all of the args are hidden

Copy link
Owner

@remkop remkop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are very close now.
For positional parameters, the man page now correctly does not show an == Arguments header if all positionals are either hidden, or part of a group (so it will be shown under the group header).

We should do the same for the == Options header.

if (iter.next().hidden()) {
iter.remove();
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is the right approach, but we should do this at the top of this method, before rendering the == Options header.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, I missed that one, i just pushed an update

@remkop
Copy link
Owner

remkop commented May 28, 2020

It may be good to have a test for the case where all options are hidden.

@remkop remkop merged commit 4e14674 into remkop:master May 28, 2020
@remkop
Copy link
Owner

remkop commented May 28, 2020

I went ahead and merged this into master.
Thank you for the contribution!

@bdemers bdemers deleted the hidden-man-options branch May 28, 2020 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: codegen An issue or change related to the picocli-codegen module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ManPageGenerator does not ignore "hidden" options
3 participants