list_commands.c (708B)
1 #include <stdio.h> 2 #include <string.h> 3 4 #include "../common.h" 5 #include "list_commands.h" 6 7 int cli_cmd_list_commands(int argc, const char **argv) { 8 (void)argc; 9 (void)argv; 10 int len; 11 int name_longest = 0; 12 struct cli_command *cmd = cli_commands; 13 while(cmd) { 14 len = (int)strlen(cmd->cmd); 15 if (len > name_longest) { name_longest = len; } 16 cmd = cmd->next; 17 } 18 19 int width = cli_get_output_width(80); 20 int left_col = name_longest + 3; 21 22 printf("\n"); 23 printf("Available commands:\n"); 24 cmd = cli_commands; 25 while (cmd) { 26 printf("\n %*s ", name_longest, cmd->cmd); 27 cli_print_wrapped(stdout, cmd->desc, width, left_col); 28 cmd = cmd->next; 29 } 30 printf("\n\n"); 31 32 return 0; 33 }