Output all command help, filtering by group or command name. */
| 639 | |
| 640 | /* Output all command help, filtering by group or command name. */ |
| 641 | static void cliOutputHelp(int argc, char **argv) { |
| 642 | int i, j, len; |
| 643 | int group = -1; |
| 644 | helpEntry *entry; |
| 645 | struct commandHelp *help; |
| 646 | |
| 647 | if (argc == 0) { |
| 648 | cliOutputGenericHelp(); |
| 649 | return; |
| 650 | } else if (argc > 0 && argv[0][0] == '@') { |
| 651 | len = sizeof(commandGroups)/sizeof(char*); |
| 652 | for (i = 0; i < len; i++) { |
| 653 | if (strcasecmp(argv[0]+1,commandGroups[i]) == 0) { |
| 654 | group = i; |
| 655 | break; |
| 656 | } |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | assert(argc > 0); |
| 661 | for (i = 0; i < helpEntriesLen; i++) { |
| 662 | entry = &helpEntries[i]; |
| 663 | if (entry->type != CLI_HELP_COMMAND) continue; |
| 664 | |
| 665 | help = entry->org; |
| 666 | if (group == -1) { |
| 667 | /* Compare all arguments */ |
| 668 | if (argc <= entry->argc) { |
| 669 | for (j = 0; j < argc; j++) { |
| 670 | if (strcasecmp(argv[j],entry->argv[j]) != 0) break; |
| 671 | } |
| 672 | if (j == argc) { |
| 673 | cliOutputCommandHelp(help,1); |
| 674 | } |
| 675 | } |
| 676 | } else { |
| 677 | if (group == help->group) { |
| 678 | cliOutputCommandHelp(help,0); |
| 679 | } |
| 680 | } |
| 681 | } |
| 682 | printf("\r\n"); |
| 683 | } |
| 684 | |
| 685 | /* Linenoise completion callback. */ |
| 686 | static void completionCallback(const char *buf, linenoiseCompletions *lc) { |
no test coverage detected