Add option grouping support to openssl apps#9920
Add option grouping support to openssl apps#9920jon-oracle wants to merge 4 commits intoopenssl:masterfrom
Conversation
apps/pkcs12.c
Outdated
|
|
||
| const char* pkcs12_opt_groups[] = { | ||
| "General", "Password", "Encryption", "MAC", "CA Certificate", "Attribute", "Input", "Output" | ||
| }; |
There was a problem hiding this comment.
I would very much prefer if there was a struct { int groupnum; const char *groupname } for the elements of this array, so it could be given like this:
struct GROUPS pkcs12_groups[] = {
{ OPT_GRP_GENERAL, "General" },
{ OPT_GRP_PASSWORD, "Password" },
{ OPT_GRP_ENCRYPT, "Encryption" },
{ OPT_GRP_MAC, "MAC" },
{ OPT_GRP_CA, "CA Certificate" },
{ OPT_GRP_ATTR, "Attribute" },
{ OPT_GRP_INPUT, "Input" },
{ OPT_GRP_OUTPUT, "Output" },
};(incidently, there's already a type you can use rather than defining GROUP, called OSSL_ITEM, found in include/openssl/core.h)
Having to synchronise the positions in an array with a separate enum is a maintenance problem waiting to happen. We've had that in the past, which is why I'm pushing for something that makes the connection more explicit.
|
Do you have a plan to apply this to all the commands - at least all of them which have more than a few options? |
|
This really isn't needed. Diff: ; g diff
diff --git a/apps/pkcs12.c b/apps/pkcs12.c
index a893553..f188502 100644
--- a/apps/pkcs12.c
+++ b/apps/pkcs12.c
@@ -61,9 +61,11 @@ typedef enum OPTION_choice {
} OPTION_CHOICE;
const OPTIONS pkcs12_options[] = {
+ {OPT_HELP_STR, 1, '-', "General commands:\n"},
{"help", OPT_HELP, '-', "Display this summary"},
{"nokeys", OPT_NOKEYS, '-', "Don't output private keys"},
{"keyex", OPT_KEYEX, '-', "Set MS key exchange type"},
+ {OPT_HELP_STR, 1, '-', "Other commands:\n"},
{"keysig", OPT_KEYSIG, '-', "Set MS key signature type"},
{"nocerts", OPT_NOCERTS, '-', "Don't output certificates"},
{"clcerts", OPT_CLCERTS, '-', "Only output client certificates"},
; |
|
And, of course you can make it more explicit by doing something like this: But beware Perlis's quote :) |
|
I actually like @richsalz's solution. It's simple, it makes the groups immediately visible, ... |
|
|
It’s #3 in the epigrams :)
Also, Andy was strongly opposed to this kind of thing.
|
Yeah this does look clean :) I've added something similar to this instead. |
| char start[80 + 1]; | ||
|
|
||
| /* Starts with its own help message? */ | ||
| standard_prolog = list[0].name != OPT_HELP_STR; |
There was a problem hiding this comment.
Soooo... this is a bit of a probem. What if someone, somewhere, has this:
const OPTIONS foo[] = {
OPT_SECTION("General"),
...How to decide it the resulting OPTIONS item is a section start or a usage?
One quick and fairly easy solution is to have another magic string called OPT_USAGE_STR and replace all things looking like this:
{OPT_HELP_STR, 1, '-'. "Usage: ..."},with
{OPT_USAGE_STR, 1, '-'. "Usage: ..."},There was a problem hiding this comment.
The other option is to have a magic OPT_SECTION_STR instead of re-using OPT_HELP_STR. That's probably going to be less work.
There was a problem hiding this comment.
Yeah using OPT_SECTION_STR seems like a smaller change that won't break what's already there.
That would maybe take quite a bit of time and should be outside the scope of this PR. I can imagine there are going to be items that belong to multiple subgroups somewhere.. |
levitte
left a comment
There was a problem hiding this comment.
So, I like this! Assuming the CIs do to, I'm all for it.
|
Would this need to be in 1_1_1 ? |
... nah. Or well, I dunno, but don't see that as necessary |
|
I do not think this belongs to 1_1_1. |
Jon will be busy on other projects - so the answer is no. |
|
I think it's fine for this PR to serve as inspiration to others. |
I understand that, but it's too bad. One of the nice things about the commands is that the flags parsing and behavior for common options is that, starting with 1.1, they all became consistent -- and had consistent help. I did most of that work, so I'm biased, but I think that was a big step forward for OpenSSL's usability. It is a shame to step back from that. Perhaps this PR can just do any infrastructure changes and wait until someone steps up to do the grouping of command flags. |
Considering what @slontis said about @jon-oracle, I would refrain from making many more demands. I'm thinking of taking this up myself, should no one else take up the gauntlet, but not immediately... I've already quite a bunch of things in my queue. |
|
I am asking him to do less. Remove the |
And put them in a second PR? that will be on hold.. |
yes. |
|
I think you and I mean different things, @richsalz. Undoing is yet another thing to do. |
It's less work than following this thread, ain't it: |
b25eaa0 to
c9488fd
Compare
Your git-fu is better than mine ;) I think the last force push did the trick, let me know if it didn't. |
|
Can you change the commit message and title now that this does something different from its original purpose.. |
c9488fd to
b9ea711
Compare
Reviewed-by: Richard Levitte <[email protected]> Reviewed-by: Shane Lontis <[email protected]> (Merged from #9920)
|
Thanks for reviewing. Merged to master. |
Added a way to group options which is backward compatible with existing apps. The new function is opt_help_ex() which accepts a set of option groups.
As an example the output from 'openssl pkcs12 --help' could be changed to: