sfdisk: add --output <list> for print command(s)

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2014-10-03 12:40:19 +02:00
parent fff8ad5882
commit 01f9286cb1
2 changed files with 24 additions and 6 deletions

View File

@ -108,15 +108,18 @@ backup file name is ~/sfdisk-<device>-<offset>.bak, see \fI\-\-backup-file\fR.
.BR \-f , " \-\-force"
Disable all consistency checking.
.TP
.BR \-o , " \-\-output " \fIlist\fP
Specify which output columns to print. Use
.B \-\-help
to get a list of all supported columns.
The default list of columns may be extended if \fIlist\fP is
specified in the format \fI+list\fP (e.g. \fB-o +UUID\fP).
.TP
.BR \-O , " \-\-backup-file " \fIpath\fR
Override default backup file name. Note that the device name and offset is always
appended to the file name.
.TP
.BR \-X , " \-\-label \fItype\fR
Specify disk label type (e.g. dos, gpt, ...). If no label specified then sfdisk
defaults to an existing label. If there is no label on the device than defaults
to "dos".
.TP
.BR \-q , " \-\-quiet"
Suppress extra info messages.
.TP
@ -133,6 +136,11 @@ Deprecated option. The sector unit is supported only.
Deprecated and ignored option. Linux (and another moder OS) compatible
partitioning is the default.
.TP
.BR \-X , " \-\-label \fItype\fR
Specify disk label type (e.g. dos, gpt, ...). If no label specified then sfdisk
defaults to an existing label. If there is no label on the device than defaults
to "dos".
.TP
.BR \-h , " \-\-help"
Display help text and exit.
.TP

View File

@ -1306,6 +1306,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE *out)
fputs(_(" -A, --append append partitions to existing partition table\n"), out);
fputs(_(" -b, --backup backup partition table sectors (see -O)\n"), out);
fputs(_(" -f, --force disable all consistency checking\n"), out);
fputs(_(" -o, --output <list> output columns\n"), out);
fputs(_(" -O, --backup-file <path> override default backout file name\n"), out);
fputs(_(" -N, --partno <num> specify partition number\n"), out);
fputs(_(" -X, --label <name> specify label type (dos, gpt, ...)\n"), out);
@ -1320,6 +1321,8 @@ static void __attribute__ ((__noreturn__)) usage(FILE *out)
fputs(USAGE_HELP, out);
fputs(USAGE_VERSION, out);
list_available_columns(out);
fprintf(out, USAGE_MAN_TAIL("sfdisk(8)"));
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
@ -1327,6 +1330,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE *out)
int main(int argc, char *argv[])
{
const char *outarg = NULL;
int rc = -EINVAL, c, longidx = -1;
struct sfdisk _sf = {
.partno = -1
@ -1356,6 +1360,7 @@ int main(int argc, char *argv[])
{ "list-types", no_argument, NULL, 'T' },
{ "no-act", no_argument, NULL, 'n' },
{ "no-reread", no_argument, NULL, OPT_NOREREAD },
{ "output", required_argument, NULL, 'o' },
{ "partno", required_argument, NULL, 'N' },
{ "show-size", no_argument, NULL, 's' },
{ "show-geometry", no_argument, NULL, 'g' },
@ -1383,7 +1388,7 @@ int main(int argc, char *argv[])
textdomain(PACKAGE);
atexit(close_stdout);
while ((c = getopt_long(argc, argv, "aAbcdfghlLO:nN:qsTu:vVX:",
while ((c = getopt_long(argc, argv, "aAbcdfghlLo:O:nN:qsTu:vVX:",
longopts, &longidx)) != -1) {
switch(c) {
case 'a':
@ -1423,6 +1428,9 @@ int main(int argc, char *argv[])
case 'L':
warnx(_("--Linux option is unnecessary and deprecated"));
break;
case 'o':
outarg = optarg;
break;
case 'O':
sf->backup = 1;
sf->backup_file = optarg;
@ -1481,6 +1489,8 @@ int main(int argc, char *argv[])
}
sfdisk_init(sf);
if (outarg)
init_fields(NULL, outarg, NULL);
if (sf->verify && !sf->act)
sf->act = ACT_VERIFY; /* --verify make be used with --list too */