]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
cfdisk: add long options to the command
authorSami Kerola <kerolasa@iki.fi>
Sat, 13 Apr 2013 19:54:32 +0000 (20:54 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 20 May 2013 11:40:15 +0000 (13:40 +0200)
Includes update to bash completion, and manual as well.

[kzak@redhat.com: - remove <<< syntax from bash-completion script]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
bash-completion/cfdisk
fdisks/cfdisk.8
fdisks/cfdisk.c

index 6cd9d6f7e590bbb8c92394b1e8e373c206365c80..6d900706a17c874687c275c2b4cafb91c5a14059 100644 (file)
@@ -5,25 +5,37 @@ _cfdisk_module()
        cur="${COMP_WORDS[COMP_CWORD]}"
        prev="${COMP_WORDS[COMP_CWORD-1]}"
        case $prev in
-               '-c')
+               '-c'|'--cylinders')
                        COMPREPLY=( $(compgen -W "cylinders" -- $cur) )
                        return 0
                        ;;
-               '-h')
+               '-h'|'--heads')
                        COMPREPLY=( $(compgen -W "heads" -- $cur) )
                        return 0
                        ;;
-               '-s')
+               '-s'|'--sectors')
                        COMPREPLY=( $(compgen -W "sectors" -- $cur) )
                        return 0
                        ;;
-               '-v')
+               '-P'|'--print')
+                       COMPREPLY=( $(compgen -W "r s t" -- $cur) )
+                       return 0
+                       ;;
+               '-v'|'-V'|'--version'|'--help')
                        return 0
                        ;;
        esac
        case $cur in
                -*)
-                       OPTS="-a -z -c -h -s"
+                       OPTS="  --cylinders
+                               --heads
+                               --sectors
+                               --guess
+                               --print
+                               --zero
+                               --arrow
+                               --help
+                               --version"
                        COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
                        return 0
                        ;;
@@ -31,7 +43,7 @@ _cfdisk_module()
        local DEV TYPE DEVICES=''
        while read DEV TYPE; do
                [ $TYPE = 'disk' ] && DEVICES+="$DEV "
-       done < <(lsblk -pnro name,type)
+       done < <(lsblk -pnro "name,type")
        COMPREPLY=( $(compgen -W "$DEVICES" -- $cur) )
        return 0
 }
index be88fdba34bce8c4848c2576df35f6f34197163f..efd33ce70ca4a3672a307b2ac9b9ddb93085e0b4 100644 (file)
@@ -11,7 +11,7 @@
 .\" permission notice identical to this one.
 .\"
 .\" " for hilit mode
-.TH CFDISK 8 "July 2009" "util-linux" "System Administration"
+.TH CFDISK 8 "April 2013" "util-linux" "System Administration"
 .SH NAME
 cfdisk \- display or manipulate disk partition table
 .SH SYNOPSIS
@@ -397,18 +397,18 @@ When in a sub-menu or at a prompt to enter a filename, you can hit the
 key to return to the main command line.
 .SH OPTIONS
 .TP
-.B \-a
+\fB\-a\fR, \fB\-\-arrow\fR
 Use an arrow cursor instead of reverse video for highlighting the
 current partition.
 .TP
-.B \-g
+\fB\-g\fR, \fB\-\-guess\fR
 Do not use the geometry given by the disk driver, but try to
 guess a geometry from the partition table.
 .TP
-.B \-v
+\fB\-v\fR, \fB\-V\fR, \fB\-\-version\fR
 Print the version number and copyright.
 .TP
-.B \-z
+\fB\-z\fR, \fB\-\-zero\fR
 Start with zeroed partition table.  This option is useful when you
 want to repartition your entire disk.
 .I Note:
@@ -416,17 +416,17 @@ this option does not zero the partition table on the disk; rather, it
 simply starts the program without reading the existing partition
 table.
 .TP
-.BI \-c " cylinders"
+\fB\-c\fR, \fB\-\-cylinders\fR \fcylinders\fR
 .TP
-.BI \-h " heads"
+\fB\-h\fR, \fB\-\-heads\fR \fIheads\fR
 .TP
-.BI \-s " sectors-per-track"
+\fB\-s\fR, \fB\-\-sectors\fR \fsectors-per-track\fR
 Override the number of cylinders, heads and sectors per track read
 from the BIOS.  If your BIOS or adapter does not supply this
 information or if it supplies incorrect information, use these options
 to set the disk geometry values.
 .TP
-.BI \-P " opt"
+\fB\-P\fR, \fB\-\-print\fR \fIr|s|t\fR
 Prints the partition table in specified formats.
 .I opt
 can be one or more of "r", "s" or "t".  See the
index 76a7aae26eb93fc9fe98ee7f956570dc7614436b..ee03cd9f562c4be8d0f1c50c257ca272ad29501e 100644 (file)
@@ -2753,27 +2753,25 @@ copyright(void) {
     fprintf(stderr, _("Copyright (C) 1994-2002 Kevin E. Martin & aeb\n"));
 }
 
-static void
-usage(char *prog_name) {
-    /* Unfortunately, xgettext does not handle multi-line strings */
-    /* so, let's use explicit \n's instead */
-    fprintf(stderr, _("\n"
-"Usage:\n"
-"Print version:\n"
-"        %s -v\n"
-"Print partition table:\n"
-"        %s -P {r|s|t} [options] device\n"
-"Interactive use:\n"
-"        %s [options] device\n"
-"\n"
-"Options:\n"
-"-a: Use arrow instead of highlighting;\n"
-"-z: Start with a zero partition table, instead of reading the pt from disk;\n"
-"-c C -h H -s S: Override the kernel's idea of the number of cylinders,\n"
-"                the number of heads and the number of sectors/track.\n\n"),
-    prog_name, prog_name, prog_name);
 
+static void __attribute__ ((__noreturn__)) usage(FILE *out)
+{
+    fputs(USAGE_HEADER, out);
+    fprintf(out, _(" %s [options] device\n"), program_invocation_short_name);
+    fputs(USAGE_OPTIONS, out);
+    fputs(_(" -c, --cylinders <number>  set the number of cylinders to use\n"), out);
+    fputs(_(" -h, --heads <number>      set the number of heads to use\n"), out);
+    fputs(_(" -s, --sectors <number>    set the number of sectors to use\n"), out);
+    fputs(_(" -g, --guess               guess a geometry from partition table\n"), out);
+    fputs(_(" -P, --print <r|s|t>       print partition table in specified format\n"), out);
+    fputs(_(" -z, --zero                start with zeroed partition table\n"), out);
+    fputs(_(" -a, --arrow               use arrow for highlighting the current partition\n"), out);
+    fputs(USAGE_SEPARATOR, out);
+    fputs(_("     --help     display this help and exit\n"), out);
+    fputs(USAGE_VERSION, out);
+    fprintf(out, USAGE_MAN_TAIL("cfdisk(8)"));
     copyright();
+    exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
 }
 
 int
@@ -2782,12 +2780,29 @@ main(int argc, char **argv)
     int c;
     int i, len;
 
+    enum {
+       OPT_HELP = CHAR_MAX + 1,
+    };
+
+    static const struct option longopts[] = {
+       {"cylinders", required_argument, 0, 'c'},
+       {"heads", required_argument, 0, 'h'},
+       {"sectors", required_argument, 0, 's'},
+       {"guess", no_argument, 0, 'g'},
+       {"print", required_argument, 0, 'P'},
+       {"zero", no_argument, 0, 'z'},
+       {"arrow", no_argument, 0, 'a'},
+       {"help", no_argument, 0, OPT_HELP},
+       {"version", no_argument, 0, 'V'},
+       {NULL, no_argument, 0, '0'},
+    };
+
     setlocale(LC_ALL, "");
     bindtextdomain(PACKAGE, LOCALEDIR);
     textdomain(PACKAGE);
     atexit(close_stdout);
 
-    while ((c = getopt(argc, argv, "ac:gh:s:vzP:")) != -1)
+    while ((c = getopt_long(argc, argv, "ac:gh:s:vVzP:", longopts, NULL)) != -1)
        switch (c) {
        case 'a':
            arrow_cursor = TRUE;
@@ -2817,9 +2832,10 @@ main(int argc, char **argv)
            }
            break;
        case 'v':
-           fprintf(stderr, "cfdisk (%s)\n", PACKAGE_STRING);
+       case 'V':
+           printf(UTIL_LINUX_VERSION);
            copyright();
-           exit(0);
+           return EXIT_SUCCESS;
        case 'z':
            zero_table = TRUE;
            break;
@@ -2837,21 +2853,20 @@ main(int argc, char **argv)
                    print_only |= PRINT_PARTITION_TABLE;
                    break;
                default:
-                   usage(argv[0]);
-                   exit(1);
+                   usage(stderr);
                }
            }
            break;
+       case OPT_HELP:
+           usage(stdout);
        default:
-           usage(argv[0]);
-           exit(1);
+           usage(stderr);
        }
 
     if (argc-optind == 1)
        disk_device = argv[optind];
     else if (argc-optind != 0) {
-       usage(argv[0]);
-       exit(1);
+       usage(stderr);
     } else if ((fd = open(DEFAULT_DEVICE, O_RDONLY)) < 0)
        disk_device = ALTERNATE_DEVICE;
     else close(fd);