From: Martin Kletzander Date: Thu, 6 Mar 2014 15:53:53 +0000 (+0100) Subject: virsh: Sort options alphabetically X-Git-Tag: v1.2.3-rc1~331 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb235130fed239ceb9484a4a74d1936b6d0beba2;p=thirdparty%2Flibvirt.git virsh: Sort options alphabetically Man page, help output and also parsing is sorted in order to find options smoothly. Signed-off-by: Martin Kletzander --- diff --git a/tools/virsh.c b/tools/virsh.c index 2d4aaff34b..9b8429f875 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -3110,16 +3110,16 @@ vshUsage(void) "\n%s [options]... [args...]\n\n" " options:\n" " -c | --connect=URI hypervisor connection URI\n" - " -r | --readonly connect readonly\n" " -d | --debug=NUM debug level [0-4]\n" + " -e | --escape set escape sequence for console\n" " -h | --help this help\n" + " -l | --log=FILE output logging to file\n" " -q | --quiet quiet mode\n" + " -r | --readonly connect readonly\n" " -t | --timing print timing information\n" - " -l | --log=FILE output logging to file\n" " -v short version\n" " -V long version\n" " --version[=TYPE] version, TYPE is short or long (default short)\n" - " -e | --escape set escape sequence for console\n\n" " commands (non interactive mode):\n\n"), progname, progname); for (grp = cmdGroups; grp->name; grp++) { @@ -3306,23 +3306,27 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) size_t i; int longindex = -1; struct option opt[] = { + {"connect", required_argument, NULL, 'c'}, {"debug", required_argument, NULL, 'd'}, + {"escape", required_argument, NULL, 'e'}, {"help", no_argument, NULL, 'h'}, + {"log", required_argument, NULL, 'l'}, {"quiet", no_argument, NULL, 'q'}, + {"readonly", no_argument, NULL, 'r'}, {"timing", no_argument, NULL, 't'}, {"version", optional_argument, NULL, 'v'}, - {"connect", required_argument, NULL, 'c'}, - {"readonly", no_argument, NULL, 'r'}, - {"log", required_argument, NULL, 'l'}, - {"escape", required_argument, NULL, 'e'}, {NULL, 0, NULL, 0} }; /* Standard (non-command) options. The leading + ensures that no * argument reordering takes place, so that command options are * not confused with top-level virsh options. */ - while ((arg = getopt_long(argc, argv, "+:d:hqtc:vVrl:e:", opt, &longindex)) != -1) { + while ((arg = getopt_long(argc, argv, "+:c:d:e:hl:qrtvV", opt, &longindex)) != -1) { switch (arg) { + case 'c': + VIR_FREE(ctl->name); + ctl->name = vshStrdup(ctl, optarg); + break; case 'd': if (virStrToLong_i(optarg, NULL, 10, &debug) < 0) { vshError(ctl, _("option %s takes a numeric argument"), @@ -3335,19 +3339,36 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) else ctl->debug = debug; break; + case 'e': + len = strlen(optarg); + + if ((len == 2 && *optarg == '^' && + vshAllowedEscapeChar(optarg[1])) || + (len == 1 && *optarg != '^')) { + ctl->escapeChar = optarg; + } else { + vshError(ctl, _("Invalid string '%s' for escape sequence"), + optarg); + exit(EXIT_FAILURE); + } + break; case 'h': vshUsage(); exit(EXIT_SUCCESS); break; + case 'l': + vshCloseLogFile(ctl); + ctl->logfile = vshStrdup(ctl, optarg); + vshOpenLogFile(ctl); + break; case 'q': ctl->quiet = true; break; case 't': ctl->timing = true; break; - case 'c': - VIR_FREE(ctl->name); - ctl->name = vshStrdup(ctl, optarg); + case 'r': + ctl->readonly = true; break; case 'v': if (STRNEQ_NULLABLE(optarg, "long")) { @@ -3358,27 +3379,6 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) case 'V': vshShowVersion(ctl); exit(EXIT_SUCCESS); - case 'r': - ctl->readonly = true; - break; - case 'l': - vshCloseLogFile(ctl); - ctl->logfile = vshStrdup(ctl, optarg); - vshOpenLogFile(ctl); - break; - case 'e': - len = strlen(optarg); - - if ((len == 2 && *optarg == '^' && - vshAllowedEscapeChar(optarg[1])) || - (len == 1 && *optarg != '^')) { - ctl->escapeChar = optarg; - } else { - vshError(ctl, _("Invalid string '%s' for escape sequence"), - optarg); - exit(EXIT_FAILURE); - } - break; case ':': for (i = 0; opt[i].name != NULL; i++) { if (opt[i].val == optopt) diff --git a/tools/virsh.pod b/tools/virsh.pod index cafbb9a1c9..cefce1bb6a 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -52,21 +52,6 @@ The B program understands the following I. =over 4 -=item B<-h>, B<--help> - -Ignore all other arguments, and behave as if the B command were -given instead. - -=item B<-v>, B<--version[=short]> - -Ignore all other arguments, and prints the version of the libvirt library -virsh is coming from - -=item B<-V>, B<--version=long> - -Ignore all other arguments, and prints the version of the libvirt library -virsh is coming from and which options and driver are compiled in. - =item B<-c>, B<--connect> I Connect to the specified I, as if by the B command, @@ -78,6 +63,17 @@ Enable debug messages at integer I and above. I can range from 0 to 4 (default). See the documentation of B environment variable below for the description of each I. +=item B<-e>, B<--escape> I + +Set alternative escape sequence for I command. By default, +telnet's B<^]> is used. Allowed characters when using hat notation are: +alphabetic character, @, [, ], \, ^, _. + +=item B<-h>, B<--help> + +Ignore all other arguments, and behave as if the B command were +given instead. + =item B<-l>, B<--log> I Output logging details to I. @@ -95,11 +91,15 @@ option of the B command. Output elapsed time information for each command. -=item B<-e>, B<--escape> I +=item B<-v>, B<--version[=short]> -Set alternative escape sequence for I command. By default, -telnet's B<^]> is used. Allowed characters when using hat notation are: -alphabetic character, @, [, ], \, ^, _. +Ignore all other arguments, and prints the version of the libvirt library +virsh is coming from + +=item B<-V>, B<--version=long> + +Ignore all other arguments, and prints the version of the libvirt library +virsh is coming from and which options and driver are compiled in. =back