Repository navigation
Conversation
…mand This change to fix the behavior of arg_cmd_disptach to match the documentation for the function. from argtable3.h documentation: If the sub-command is found, its handler function is called with the given arguments and context. If the sub-command is not found, **an error message may be written to the result buffer, and a nonzero error code is returned.** but current behavior if command is not found is raises an assertion error. Example of output from the multicmd example: ``` multicmd: vendored/argtable3.c:4966: arg_cmd_dispatch: Assertion `cmd_info != NULL' failed. Aborted (core dumped) multicmd lit ```
Author
|
The help command seems to be broken after this change. |
Contributor
|
@salahfh: The reason why I use |
Author
|
@tomghuang I've tried to work based on |
Contributor
|
@salahfh: Very good point. To prevent this, before calling /**
* Searches for a sub-command by key using the sub-command iterator.
*
* The `arg_cmd_itr_search` function searches the sub-command table for a
* sub-command whose key matches the specified value, starting from the current
* position of the iterator. If a match is found, the iterator is positioned at
* the found entry.
*
* This function is useful for efficiently locating a specific sub-command in
* applications that support multiple commands (such as `git` or `docker`-style
* interfaces), especially when iterating over or managing a dynamic set of
* sub-commands.
*
* Example usage:
* ```
* arg_cmd_itr_t itr = arg_cmd_itr_create();
* if (arg_cmd_itr_search(itr, "list")) {
* arg_cmd_info_t* info = arg_cmd_itr_value(itr);
* printf("Found sub-command: %s - %s\n", info->name, info->description);
* }
* arg_cmd_itr_destroy(itr);
* ```
*
* @param itr The sub-command iterator.
* @param k The key to search for (typically a string with the sub-command
* name).
* @return 1 if the key is found and the iterator is positioned at the entry,
* 0 otherwise.
*
* @see arg_cmd_itr_create, arg_cmd_itr_value, arg_cmd_info_t
*/
ARG_EXTERN int arg_cmd_itr_search(arg_cmd_itr_t itr, void* k); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi,
I've started learning C and experiementing wtih CLI arg parsing for small program. While using this library, I've encountered the issue arg_cmd_disptach assertion failing and not allowing the program to handle the error.
I'd like to share this PR to fix this behavior to match the documentation. Also I've included some more details in the commit message.
Please review and merge if it's correct.
Thank you :)