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

Support "Hidden" Commands #46

Closed
wants to merge 4 commits into from
Closed

Conversation

mtgstuber
Copy link
Contributor

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.

Michael Garrison Stuber and others added 4 commits January 15, 2024 22:59
Copy link

codecov bot commented Jan 16, 2024

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 ⚠️
examples/linux-example/main.cpp 0.00% 1 Missing ⚠️
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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@funbiscuit
Copy link
Owner

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
Copy link
Owner

Closing as stale.

@funbiscuit funbiscuit closed this May 18, 2024
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