From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: kerolasa@iki.fi
Subject: [PATCH 04/33] cfdisk: add long options to the command
Date: Sat, 13 Apr 2013 20:54:32 +0100 [thread overview]
Message-ID: <1365882901-11429-5-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1365882901-11429-1-git-send-email-kerolasa@iki.fi>
Includes update to bash completion, and manual as well.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
bash-completion/cfdisk | 24 ++++++++++++-----
fdisks/cfdisk.8 | 18 ++++++-------
fdisks/cfdisk.c | 71 ++++++++++++++++++++++++++++++--------------------
3 files changed, 70 insertions(+), 43 deletions(-)
diff --git a/bash-completion/cfdisk b/bash-completion/cfdisk
index 6cd9d6f..65039ee 100644
--- a/bash-completion/cfdisk
+++ b/bash-completion/cfdisk
@@ -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
}
diff --git a/fdisks/cfdisk.8 b/fdisks/cfdisk.8
index be88fdb..efd33ce 100644
--- a/fdisks/cfdisk.8
+++ b/fdisks/cfdisk.8
@@ -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
diff --git a/fdisks/cfdisk.c b/fdisks/cfdisk.c
index 136ff9d..db9e233 100644
--- a/fdisks/cfdisk.c
+++ b/fdisks/cfdisk.c
@@ -2737,27 +2737,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
@@ -2766,12 +2764,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;
@@ -2801,9 +2816,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;
@@ -2821,21 +2837,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);
--
1.8.2.1
next prev parent reply other threads:[~2013-04-13 19:55 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-13 19:54 [PATCH 00/33] pull: bash completions, help screens, and file writing Sami Kerola
2013-04-13 19:54 ` [PATCH 01/33] bash-completion: add mount and umount Sami Kerola
2013-04-13 19:54 ` [PATCH 02/33] blkid, hwclock, ldattach: use program_invocation_short_name Sami Kerola
2013-04-13 19:54 ` [PATCH 03/33] utmpdump: add option to write to a file Sami Kerola
2013-04-13 19:54 ` Sami Kerola [this message]
2013-04-26 11:30 ` [PATCH 04/33] cfdisk: add long options to the command Karel Zak
2013-04-13 19:54 ` [PATCH 05/33] bash-completion: prefer bash 3.x 'here string' syntax Sami Kerola
2013-04-13 21:59 ` Dave Reisner
2013-04-26 11:38 ` Karel Zak
2013-04-26 12:29 ` Sami Kerola
2013-04-13 19:54 ` [PATCH 06/33] setpriv: allow login and group name option arguments Sami Kerola
2013-04-13 19:54 ` [PATCH 07/33] build-sys: add --disable-setterm to ./configure Sami Kerola
2013-04-26 11:53 ` Karel Zak
2013-04-13 19:54 ` [PATCH 08/33] hexdump: add long options to the command Sami Kerola
2013-04-13 19:54 ` [PATCH 09/33] setsid: exit when control terminal cannot be set Sami Kerola
2013-04-13 19:54 ` [PATCH 10/33] cfdisk: check writing to a file was successful Sami Kerola
2013-04-13 19:54 ` [PATCH 11/33] setpriv: " Sami Kerola
2013-04-13 19:54 ` [PATCH 12/33] agetty: " Sami Kerola
2013-04-13 19:54 ` [PATCH 13/33] pg: " Sami Kerola
2013-04-13 19:54 ` [PATCH 14/33] libblkid: " Sami Kerola
2013-04-13 19:54 ` [PATCH 15/33] libmount: " Sami Kerola
2013-04-13 19:54 ` [PATCH 16/33] include: add close_fd() for noticing write errors before close() Sami Kerola
2013-04-13 19:54 ` [PATCH 17/33] fdformat: check writing to a file descriptor was successful Sami Kerola
2013-04-13 19:54 ` [PATCH 18/33] partx: " Sami Kerola
2013-04-13 19:54 ` [PATCH 19/33] resizepart: " Sami Kerola
2013-04-13 19:54 ` [PATCH 20/33] cfdisk: " Sami Kerola
2013-04-13 19:54 ` [PATCH 21/33] sfdisk: " Sami Kerola
2013-04-13 19:54 ` [PATCH 22/33] wdctl: " Sami Kerola
2013-04-13 19:54 ` [PATCH 23/33] fsck.cramfs: " Sami Kerola
2013-04-13 19:54 ` [PATCH 24/33] fsck.minix: " Sami Kerola
2013-04-13 19:54 ` [PATCH 25/33] mkfs.bfs: " Sami Kerola
2013-04-13 19:54 ` [PATCH 26/33] mkfs.cramfs: unify write check to a file descriptor Sami Kerola
2013-04-13 19:54 ` [PATCH 27/33] mkfs.minix: check writing to a file descriptor was successful Sami Kerola
2013-04-13 19:54 ` [PATCH 28/33] mkswap: unify write check to a file descriptor Sami Kerola
2013-04-13 19:54 ` [PATCH 29/33] swaplabel: check writing to a file descriptor was successful Sami Kerola
2013-04-13 19:54 ` [PATCH 30/33] fallocate: " Sami Kerola
2013-04-13 19:54 ` [PATCH 31/33] setpriv: " Sami Kerola
2013-04-13 19:55 ` [PATCH 32/33] swapon: " Sami Kerola
2013-04-13 19:55 ` [PATCH 33/33] wall: " Sami Kerola
2013-04-17 13:31 ` [PATCH 00/33] pull: bash completions, help screens, and file writing Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1365882901-11429-5-git-send-email-kerolasa@iki.fi \
--to=kerolasa@iki.fi \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox