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

Default argument for commands #227

Open
pkbehera opened this issue Mar 15, 2024 · 1 comment
Open

Default argument for commands #227

pkbehera opened this issue Mar 15, 2024 · 1 comment

Comments

@pkbehera
Copy link

pkbehera commented Mar 15, 2024

 root_menu->Insert(
        "show_updt",
        [&](ostream& out, uint32_t cnt = 1) {
            // do stuff
            //...
        },                                                                
        "Show next x updates");

I tried registering the above handler, expecting the command to use default argument of 1, when no arguments are provided. But it did not work, though it compiled just fine:

demo> help
Commands available:
 - help
        This help message
 - exit
        Quit the session
 - show_updt <unsigned int>
        Show next x updates
demo> show_updt 
wrong command: show_updt
demo> show_updt 2
demo> show_updt 1
demo>

Default arguments if available would be great!

Also, the error message here should better be something like missing command arguments instead of wrong command!

@pkbehera pkbehera changed the title Is it possible to have default argument for commands? Default argument for commands Mar 15, 2024
@daniele77
Copy link
Owner

It would be a great feature, indeed.

Unfortunately, C++ templates do not work with default arguments, and cli library is implemented with template functions.

However, if someone in the community has already implemented a successful solution for using default arguments with template functions, please feel free to share a pull request (PR).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants