Skip to content

Add support for multiple trailing optional arguments #11

Open
nicdem-NA wants to merge 1 commit intobgomberg:masterfrom
nicdem-NA:opt-arg-support
Open

Add support for multiple trailing optional arguments #11
nicdem-NA wants to merge 1 commit intobgomberg:masterfrom
nicdem-NA:opt-arg-support

Conversation

@nicdem-NA
Copy link
Copy Markdown

@nicdem-NA nicdem-NA commented Apr 6, 2026

This PR introduces support for multiple trailing optional arguments :

  • Extend optional argument support from a single trailing optional arg to multiple consecutive trailing optional args
  • Update get_num_required_args() to walk backwards and count all trailing optional args, not just the last one
  • Update process_line() to set default values for all omitted optional args, not just one
  • Relax validate_arg_def() to no longer restrict optional args to only the last position

Example:
Previously, only the last argument of a command could be optional:

CONSOLE_COMMAND_DEF(cmd, "description",
CONSOLE_INT_ARG_DEF(required_arg, "A required arg"),
CONSOLE_OPTIONAL_INT_ARG_DEF(optional_arg, "An optional arg")  // only one allowed
); 

Now, multiple consecutive trailing arguments can be optional:

CONSOLE_COMMAND_DEF(cmd, "description",
CONSOLE_INT_ARG_DEF(required_arg, "A required arg"),
CONSOLE_OPTIONAL_INT_ARG_DEF(opt1, "First optional arg"), 
CONSOLE_OPTIONAL_INT_ARG_DEF(opt2, "Second optional arg")
);

Users can invoke this as cmd 1, cmd 1 2, or cmd 1 2 3. Omitted optional args receive CONSOLE_INT_ARG_DEFAULT or CONSOLE_STR_ARG_DEFAULT as before.

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.

1 participant