embedded-cli icon indicating copy to clipboard operation
embedded-cli copied to clipboard

Support "Hidden" Commands

Open mtgstuber opened this issue 2 years ago • 2 comments

This submission adds an additional "hidden" boolean to the command binding structure. Commands with the "hidden" bit set are not shown in the help menu or provided in autocomplete.

Why have hidden commands? One answer is synonyms. Maybe I want to have "quit" as a synonym to exit without taking up space in the help menu. Another is advanced features: Maybe I want some expert commands that aren't shown to the user.

mtgstuber avatar Jan 16 '24 07:01 mtgstuber

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (ffa8014) 82.67% compared to head (f453223) 82.09%.

Files Patch % Lines
lib/src/embedded_cli.c 57.14% 1 Missing and 2 partials :warning:
examples/linux-example/main.cpp 0.00% 1 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #46      +/-   ##
==========================================
- Coverage   82.67%   82.09%   -0.59%     
==========================================
  Files           2        2              
  Lines         560      564       +4     
  Branches      135      138       +3     
==========================================
  Hits          463      463              
- Misses         63       65       +2     
- Partials       34       36       +2     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jan 16 '24 07:01 codecov[bot]

This is a bit controversial. Adding extra argument to CliCommandBinding will force all users to provide it always, even if they don't ever need this "hidden" feature. And it's also a breaking change.

Maybe if we make a breaking change anyway, it would be better to change api of binding addition? Like so:

CliCommandBinding* embeddedCliAddBinding(EmbeddedCli *cli, const char* name)

So only command name is a required thing of a binding. And then we set only neccessary fields on returned binding itself:

CliCommandBinding* exit = embeddedCliAddBinding(cli, "exit");
exit->binding = onExit;

CliCommandBinding* quit = embeddedCliAddBinding(cli, "quit");
quit->binding = onExit;
quit->hidden = true;

Another thing that I don't like is that we're spending another byte on this bool value while we already have a tokenizeArgs flag on a binding. So probable, since this is a breaking change anyway, we should remove that flag and add new u8 called flags. And use is as bitflags. Then hidden can be renamed to autocomplete (if false, autocompletion not done). And help can be hidden if help string is null.

So tell me what do you think of these suggestions. And tell me if you're willing to add another PR first on all this command binding refactor and then update this PR to use new "binding api".

funbiscuit avatar Jan 16 '24 15:01 funbiscuit

Closing as stale.

funbiscuit avatar May 18 '24 15:05 funbiscuit