3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 13:02:44 +01:00

client: Provide '--help' command-line option

In addition, this improves the 'help' display
This commit is contained in:
Tim Kourt 2019-09-18 15:18:35 -07:00 committed by Denis Kenzior
parent d369a650ab
commit 79ccff464f

View File

@ -506,6 +506,20 @@ static void list_commands(const char *command_family,
} }
} }
static void list_cmd_options(void)
{
display(MARGIN "--%-*s%s\n", 48, COMMAND_OPTION_USERNAME,
"Provide username");
display(MARGIN "--%-*s%s\n", 48, COMMAND_OPTION_PASSWORD,
"Provide password");
display(MARGIN "--%-*s%s\n", 48, COMMAND_OPTION_PASSPHRASE,
"Provide passphrase");
display(MARGIN "--%-*s%s\n", 48, COMMAND_OPTION_DONTASK,
"Dont ask for missing\n"
"\t\t\t\t\t\t credentials");
display(MARGIN "--%-*s%s\n", 48, "help", "Display help");
}
static void list_cmd_families(void) static void list_cmd_families(void)
{ {
const struct l_queue_entry *entry; const struct l_queue_entry *entry;
@ -519,6 +533,32 @@ static void list_cmd_families(void)
} }
} }
static void command_display_help(void)
{
display("\n");
display_table_header("iwctl version " VERSION, MARGIN "%-*s",
5, "Usage");
display(MARGIN "iwctl [--options] [commands]\n");
display_table_footer();
display_table_header("Available options", MARGIN "%-*s%-*s",
50, "Options", 28, "Description");
list_cmd_options();
display_table_footer();
display_table_header("Available commands", MARGIN "%-*s%-*s",
50, "Commands", 28, "Description");
list_cmd_families();
display_table_footer();
if (!interactive_mode)
return;
display("\nMiscellaneous:\n");
list_commands(NULL, misc_commands);
}
static bool command_match_misc_commands(char **argv, int argc) static bool command_match_misc_commands(char **argv, int argc)
{ {
if (match_cmd(NULL, argv[0], argv + 1, argc - 1, misc_commands)) if (match_cmd(NULL, argv[0], argv + 1, argc - 1, misc_commands))
@ -527,17 +567,7 @@ static bool command_match_misc_commands(char **argv, int argc)
if (strcmp(argv[0], "help")) if (strcmp(argv[0], "help"))
return false; return false;
display_table_header("Available commands", MARGIN "%-*s%-*s", command_display_help();
50, "Commands", 28, "Description");
list_cmd_families();
if (!interactive_mode)
return true;
display("\nMiscellaneous:\n");
list_commands(NULL, misc_commands);
return true; return true;
} }
@ -625,6 +655,7 @@ static const struct option command_opts[] = {
{ COMMAND_OPTION_PASSWORD, required_argument, NULL, 'p' }, { COMMAND_OPTION_PASSWORD, required_argument, NULL, 'p' },
{ COMMAND_OPTION_PASSPHRASE, required_argument, NULL, 'P' }, { COMMAND_OPTION_PASSPHRASE, required_argument, NULL, 'P' },
{ COMMAND_OPTION_DONTASK, no_argument, NULL, 'd' }, { COMMAND_OPTION_DONTASK, no_argument, NULL, 'd' },
{ "help", no_argument, NULL, 'h' },
{ } { }
}; };
@ -649,7 +680,7 @@ bool command_init(char **argv, int argc)
for (;;) { for (;;) {
struct command_option *option; struct command_option *option;
opt = getopt_long(argc, argv, "u:p:P:d", command_opts, NULL); opt = getopt_long(argc, argv, "u:p:P:dh", command_opts, NULL);
switch (opt) { switch (opt) {
case 'u': case 'u':
@ -683,6 +714,12 @@ bool command_init(char **argv, int argc)
l_queue_push_tail(command_options, option); l_queue_push_tail(command_options, option);
break; break;
case 'h':
command_display_help();
l_main_quit();
return true;
case -1: case -1:
goto options_parsed; goto options_parsed;
case '?': case '?':