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" .BR \-f , " \-\-force"
Disable all consistency checking. Disable all consistency checking.
.TP .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 .BR \-O , " \-\-backup-file " \fIpath\fR
Override default backup file name. Note that the device name and offset is always Override default backup file name. Note that the device name and offset is always
appended to the file name. appended to the file name.
.TP .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" .BR \-q , " \-\-quiet"
Suppress extra info messages. Suppress extra info messages.
.TP .TP
@ -133,6 +136,11 @@ Deprecated option. The sector unit is supported only.
Deprecated and ignored option. Linux (and another moder OS) compatible Deprecated and ignored option. Linux (and another moder OS) compatible
partitioning is the default. partitioning is the default.
.TP .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" .BR \-h , " \-\-help"
Display help text and exit. Display help text and exit.
.TP .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(_(" -A, --append append partitions to existing partition table\n"), out);
fputs(_(" -b, --backup backup partition table sectors (see -O)\n"), out); fputs(_(" -b, --backup backup partition table sectors (see -O)\n"), out);
fputs(_(" -f, --force disable all consistency checking\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(_(" -O, --backup-file <path> override default backout file name\n"), out);
fputs(_(" -N, --partno <num> specify partition number\n"), out); fputs(_(" -N, --partno <num> specify partition number\n"), out);
fputs(_(" -X, --label <name> specify label type (dos, gpt, ...)\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_HELP, out);
fputs(USAGE_VERSION, out); fputs(USAGE_VERSION, out);
list_available_columns(out);
fprintf(out, USAGE_MAN_TAIL("sfdisk(8)")); fprintf(out, USAGE_MAN_TAIL("sfdisk(8)"));
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS); exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
} }
@ -1327,6 +1330,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE *out)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
const char *outarg = NULL;
int rc = -EINVAL, c, longidx = -1; int rc = -EINVAL, c, longidx = -1;
struct sfdisk _sf = { struct sfdisk _sf = {
.partno = -1 .partno = -1
@ -1356,6 +1360,7 @@ int main(int argc, char *argv[])
{ "list-types", no_argument, NULL, 'T' }, { "list-types", no_argument, NULL, 'T' },
{ "no-act", no_argument, NULL, 'n' }, { "no-act", no_argument, NULL, 'n' },
{ "no-reread", no_argument, NULL, OPT_NOREREAD }, { "no-reread", no_argument, NULL, OPT_NOREREAD },
{ "output", required_argument, NULL, 'o' },
{ "partno", required_argument, NULL, 'N' }, { "partno", required_argument, NULL, 'N' },
{ "show-size", no_argument, NULL, 's' }, { "show-size", no_argument, NULL, 's' },
{ "show-geometry", no_argument, NULL, 'g' }, { "show-geometry", no_argument, NULL, 'g' },
@ -1383,7 +1388,7 @@ int main(int argc, char *argv[])
textdomain(PACKAGE); textdomain(PACKAGE);
atexit(close_stdout); 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) { longopts, &longidx)) != -1) {
switch(c) { switch(c) {
case 'a': case 'a':
@ -1423,6 +1428,9 @@ int main(int argc, char *argv[])
case 'L': case 'L':
warnx(_("--Linux option is unnecessary and deprecated")); warnx(_("--Linux option is unnecessary and deprecated"));
break; break;
case 'o':
outarg = optarg;
break;
case 'O': case 'O':
sf->backup = 1; sf->backup = 1;
sf->backup_file = optarg; sf->backup_file = optarg;
@ -1481,6 +1489,8 @@ int main(int argc, char *argv[])
} }
sfdisk_init(sf); sfdisk_init(sf);
if (outarg)
init_fields(NULL, outarg, NULL);
if (sf->verify && !sf->act) if (sf->verify && !sf->act)
sf->act = ACT_VERIFY; /* --verify make be used with --list too */ sf->act = ACT_VERIFY; /* --verify make be used with --list too */