funbiscuit/embedded-cli

CLI options getopt

Opened this issue · 2 comments

Hello.

I am using this cli in an embedded c++ project, and it's pretty cool.
I found this getopt port and I could eventually use it by iterating on the args.

When in it comes to help, it would be great to have the possibilty to pass a string documenting the CLI args and options.
This way say we have a short description to summarize the purpose of the command, and a long one that is printed when we call help on this command.

Namely

#define LED_CMD_SYNTAX  "\
led [-p <led_id>] [<arg>]\n\
\t -p <led_id>: led id, must be 0, 1 or 2. defaults to 0.\n\
\t <arg>: toggle,on or off. defaults to toggle\
"

 CliCommandBinding led_binding = {
          .name = "led",
          .help= "Led manipulation command", // this is the short help
          .syntax=LED_CMD_SYNTAX,  // this is the long help, can be NULL if not used
          .tokenizeArgs = true,
          .context = NULL,
          .binding = onLed
  }; 

Expected output:

$ help
 * help
        Print list of commands
 * clear
        Clears the console
 * led
        Led manipulation command
$ help led
 * led
        Led manipulation command. 
        Syntax:
        led [-p <led_id>] [<arg>]
           -p <led_id>: led id, must be 0, 1 or 2. defaults to 0.
           <arg>: toggle,on or off. defaults to toggle

Can you show expected output of help command with this binding?
As for implementation, not sure that I can add it any time soon. But PRs are always welcome.

I updated the description with expected output, I'll keep you posted if I find some time to add this.