summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2017-03-03 15:12:46 -0600
committerDavid Teigland <teigland@redhat.com>2017-03-03 15:14:18 -0600
commite4ef3d04ad3a2870f94557250006e4c93431b0bb (patch)
tree237eaf77768f094c87e887a8e0c0062e33230170
parent547bdb63e1757288586ea5b74b228f35bb8d2af2 (diff)
downloadlvm2-e4ef3d04ad3a2870f94557250006e4c93431b0bb.tar.gz
help: show short opt with long opt
e.g. show -n|--name instead of just --name
-rw-r--r--tools/command.c145
1 files changed, 140 insertions, 5 deletions
diff --git a/tools/command.c b/tools/command.c
index cab6f0900..436e759f3 100644
--- a/tools/command.c
+++ b/tools/command.c
@@ -1675,9 +1675,14 @@ void print_usage(struct command *cmd, int longhelp, int desc_first)
if (cmd->ro_count) {
first = 1;
+ /* print options with short opts */
+
for (ro = 0; ro < cmd->ro_count; ro++) {
opt_enum = cmd->required_opt_args[ro].opt;
+ if (!opt_names[opt_enum].short_opt)
+ continue;
+
if ((opt_enum == size_ARG) && command_has_alternate_extents(cmd->name))
include_extents = 1;
@@ -1689,12 +1694,41 @@ void print_usage(struct command *cmd, int longhelp, int desc_first)
first = 0;
}
- printf(" %s", opt_names[cmd->required_opt_args[ro].opt].long_opt);
+ printf(" -%c|%s", opt_names[opt_enum].short_opt, opt_names[opt_enum].long_opt);
+ if (cmd->required_opt_args[ro].def.val_bits) {
+ printf(" ");
+ print_usage_def(cmd, opt_enum, &cmd->required_opt_args[ro].def);
+ }
+ }
+
+ /* print options without short opts */
+
+ for (ro = 0; ro < cmd->ro_count; ro++) {
+ opt_enum = cmd->required_opt_args[ro].opt;
+
+ if (opt_names[opt_enum].short_opt)
+ continue;
+
+ if ((opt_enum == size_ARG) && command_has_alternate_extents(cmd->name))
+ include_extents = 1;
+
+ if (onereq) {
+ if (first)
+ printf("\n\t(");
+ else {
+ printf(",\n\t ");
+ printf(" "); /* align for no short opt */
+ }
+ first = 0;
+ }
+
+ printf(" %s", opt_names[opt_enum].long_opt);
if (cmd->required_opt_args[ro].def.val_bits) {
printf(" ");
print_usage_def(cmd, opt_enum, &cmd->required_opt_args[ro].def);
}
}
+
if (onereq)
printf(" )\n");
}
@@ -1718,14 +1752,19 @@ void print_usage(struct command *cmd, int longhelp, int desc_first)
if (cmd->oo_count) {
if (include_extents) {
- printf("\n\t[ --extents ");
+ printf("\n\t[ -l|--extents ");
print_val_usage(cmd, extents_VAL);
printf(" ]");
}
+ /* print optional options with short opts */
+
for (oo = 0; oo < cmd->oo_count; oo++) {
opt_enum = cmd->optional_opt_args[oo].opt;
+ if (!opt_names[opt_enum].short_opt)
+ continue;
+
/*
* Skip common lvm options in lvm_all which
* are printed at the end under "Common options for lvm"
@@ -1749,7 +1788,47 @@ void print_usage(struct command *cmd, int longhelp, int desc_first)
printf("\n\t[");
- printf(" %s", opt_names[opt_enum].long_opt);
+ printf(" -%c|%s", opt_names[opt_enum].short_opt, opt_names[opt_enum].long_opt);
+ if (cmd->optional_opt_args[oo].def.val_bits) {
+ printf(" ");
+ print_usage_def(cmd, opt_enum, &cmd->optional_opt_args[oo].def);
+ }
+
+ printf(" ]");
+ }
+
+ /* print optional options without short opts */
+
+ for (oo = 0; oo < cmd->oo_count; oo++) {
+ opt_enum = cmd->optional_opt_args[oo].opt;
+
+ if (opt_names[opt_enum].short_opt)
+ continue;
+
+ /*
+ * Skip common lvm options in lvm_all which
+ * are printed at the end under "Common options for lvm"
+ * see print_common_options_lvm()
+ */
+
+ if (is_lvm_all_opt(opt_enum))
+ continue;
+
+ /*
+ * When there is more than one variant,
+ * skip common command options from
+ * cname->common_options (options common
+ * to all variants), which are printed at
+ * the end under "Common options for command"
+ * see print_common_options_cmd()
+ */
+
+ if ((cname->variants > 1) && cname->common_options[opt_enum])
+ continue;
+
+ printf("\n\t[");
+
+ printf(" %s", opt_names[opt_enum].long_opt);
if (cmd->optional_opt_args[oo].def.val_bits) {
printf(" ");
print_usage_def(cmd, opt_enum, &cmd->optional_opt_args[oo].def);
@@ -1794,12 +1873,35 @@ void print_usage_common_lvm(struct command_name *cname, struct command *cmd)
printf(" Common options for lvm:");
+ /* print options with short opts */
+
+ for (oo = 0; oo < lvm_all.oo_count; oo++) {
+ opt_enum = lvm_all.optional_opt_args[oo].opt;
+
+ if (!opt_names[opt_enum].short_opt)
+ continue;
+
+ printf("\n\t[");
+
+ printf(" -%c|%s", opt_names[opt_enum].short_opt, opt_names[opt_enum].long_opt);
+ if (lvm_all.optional_opt_args[oo].def.val_bits) {
+ printf(" ");
+ print_usage_def(cmd, opt_enum, &lvm_all.optional_opt_args[oo].def);
+ }
+ printf(" ]");
+ }
+
+ /* print options without short opts */
+
for (oo = 0; oo < lvm_all.oo_count; oo++) {
opt_enum = lvm_all.optional_opt_args[oo].opt;
+ if (opt_names[opt_enum].short_opt)
+ continue;
+
printf("\n\t[");
- printf(" %s", opt_names[opt_enum].long_opt);
+ printf(" %s", opt_names[opt_enum].long_opt);
if (lvm_all.optional_opt_args[oo].def.val_bits) {
printf(" ");
print_usage_def(cmd, opt_enum, &lvm_all.optional_opt_args[oo].def);
@@ -1824,6 +1926,8 @@ void print_usage_common_cmd(struct command_name *cname, struct command *cmd)
printf(" Common options for command:");
+ /* print options with short opts */
+
for (opt_enum = 0; opt_enum < ARG_COUNT; opt_enum++) {
if (!cname->common_options[opt_enum])
continue;
@@ -1831,13 +1935,44 @@ void print_usage_common_cmd(struct command_name *cname, struct command *cmd)
if (is_lvm_all_opt(opt_enum))
continue;
+ if (!opt_names[opt_enum].short_opt)
+ continue;
+
printf("\n\t[");
for (oo = 0; oo < cmd->oo_count; oo++) {
if (cmd->optional_opt_args[oo].opt != opt_enum)
continue;
- printf(" %s", opt_names[opt_enum].long_opt);
+ printf(" -%c|%s", opt_names[opt_enum].short_opt, opt_names[opt_enum].long_opt);
+ if (cmd->optional_opt_args[oo].def.val_bits) {
+ printf(" ");
+ print_usage_def(cmd, opt_enum, &cmd->optional_opt_args[oo].def);
+ }
+ break;
+ }
+ printf(" ]");
+ }
+
+ /* print options without short opts */
+
+ for (opt_enum = 0; opt_enum < ARG_COUNT; opt_enum++) {
+ if (!cname->common_options[opt_enum])
+ continue;
+
+ if (is_lvm_all_opt(opt_enum))
+ continue;
+
+ if (opt_names[opt_enum].short_opt)
+ continue;
+
+ printf("\n\t[");
+
+ for (oo = 0; oo < cmd->oo_count; oo++) {
+ if (cmd->optional_opt_args[oo].opt != opt_enum)
+ continue;
+
+ printf(" %s", opt_names[opt_enum].long_opt);
if (cmd->optional_opt_args[oo].def.val_bits) {
printf(" ");
print_usage_def(cmd, opt_enum, &cmd->optional_opt_args[oo].def);