clipp icon indicating copy to clipboard operation
clipp copied to clipboard

Don't duplicate documentation for re-used options

Open brett-harrison opened this issue 6 years ago • 3 comments

Is it possible to dedup args that are listed multiple times in different commands? Here's an example:

bool val1, val2, val3;
auto arg1 = required("--arg1").set(val1) % "doc for arg1";
auto arg2 = required("--arg2").set(val2) % "doc for arg2";
auto arg3 = required("--arg3").set(val3) % "doc for arg3";

auto cli = (command("cmd1"), arg1, arg2) | (command("cmd2"), arg2, arg3) | (command("cmd3"), arg1, arg3);
SYNOPSIS
        prog cmd1 --arg1 --arg2
        prog cmd2 --arg2 --arg3
        prog cmd3 --arg1 --arg3

OPTIONS
        --arg1      doc for arg1
        --arg2      doc for arg2
        --arg2      doc for arg2
        --arg3      doc for arg3
        --arg1      doc for arg1
        --arg3      doc for arg3

brett-harrison avatar May 29 '18 13:05 brett-harrison

Do I understand it correctly that you want to avoid that the documentation is listed multiple times? Since all parameters are copied, arg1 behind cmd1 really is a different object from arg1 behind cmd3. Currently I don't check for redundancy while generating the option documentation but it is already on my todo list.

The only quick solution I can think of is to add the documentation only once. So either:

bool val1, val2, val3;
auto arg1 = required("--arg1").set(val1) % "doc for arg1";
auto arg2 = required("--arg2").set(val2) % "doc for arg2";
auto arg3 = required("--arg3").set(val3) % "doc for arg3";

auto cli = (command("cmd1"), arg1, arg2) | (command("cmd2"), arg2 % "", arg3) | (command("cmd3"), arg1 % "", arg3 % "");

or

bool val1, val2, val3;
auto arg1 = required("--arg1").set(val1);
auto arg2 = required("--arg2").set(val2);
auto arg3 = required("--arg3").set(val3);
auto cli = 
    (command("cmd1"), arg1  % "doc for arg1", arg2 % "doc for arg2") | 
    (command("cmd2"), arg2, arg3) | 
    (command("cmd3"), arg1, arg3 % "doc for arg3");

muellan avatar May 29 '18 13:05 muellan

Yes you understand correctly. Thanks for looking into this. One alternative could be allowing a param_filter to be constructed from a lambda which takes the arg_string as an argument, and I could store my own set<string> that's captured by the lambda and returns false if I've already seen that arg string and stored it in my set.

brett-harrison avatar May 29 '18 13:05 brett-harrison

Or perhaps make operator() virtual and derive uniq_param_filter from param_filter, adding unordered_set<string> to check on flags().

vlad-ivanov-name avatar Mar 21 '19 08:03 vlad-ivanov-name