Skip to content

Commit

Permalink
btrfs-progs: convert common options to option formatter
Browse files Browse the repository at this point in the history
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
kdave committed Feb 22, 2023
1 parent 76b5561 commit cda1f14
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
4 changes: 3 additions & 1 deletion common/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ static int do_usage_one_command(const char * const *usagestr,
* commands
*/
hpad(pad, outf);
fprintf(outf, "--format TYPE where TYPE is: %s",
fprintf(outf, "%-*s where TYPE is: %s",
HELPINFO_OPTION_WIDTH,
"--format TYPE",
output_formats[0].name);
for (i = 1; i < ARRAY_SIZE(output_formats); i++) {
if (cmd_flags & output_formats[i].value)
Expand Down
45 changes: 22 additions & 23 deletions common/help.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,26 @@ struct cmd_group;

#define ARGV0_BUF_SIZE PATH_MAX

#define HELPINFO_UNITS_LONG \
"--raw raw numbers in bytes", \
"--human-readable human friendly numbers, base 1024 (default)", \
"--iec use 1024 as a base (KiB, MiB, GiB, TiB)", \
"--si use 1000 as a base (kB, MB, GB, TB)", \
"--kbytes show sizes in KiB, or kB with --si", \
"--mbytes show sizes in MiB, or MB with --si", \
"--gbytes show sizes in GiB, or GB with --si", \
"--tbytes show sizes in TiB, or TB with --si"

#define HELPINFO_UNITS_SHORT_LONG \
"-b|--raw raw numbers in bytes", \
"-h|--human-readable", \
" human friendly numbers, base 1024 (default)", \
"-H human friendly numbers, base 1000", \
"--iec use 1024 as a base (KiB, MiB, GiB, TiB)", \
"--si use 1000 as a base (kB, MB, GB, TB)", \
"-k|--kbytes show sizes in KiB, or kB with --si", \
"-m|--mbytes show sizes in MiB, or MB with --si", \
"-g|--gbytes show sizes in GiB, or GB with --si", \
"-t|--tbytes show sizes in TiB, or TB with --si"
#define HELPINFO_UNITS_LONG \
OPTLINE("--raw", "raw numbers in bytes"), \
OPTLINE("--human-readable", "human friendly numbers, base 1024 (default)"), \
OPTLINE("--iec", "use 1024 as a base (KiB, MiB, GiB, TiB)"), \
OPTLINE("--si", "use 1000 as a base (kB, MB, GB, TB)"), \
OPTLINE("--kbytes", "show sizes in KiB, or kB with --si"), \
OPTLINE("--mbytes", "show sizes in MiB, or MB with --si"), \
OPTLINE("--gbytes", "show sizes in GiB, or GB with --si"), \
OPTLINE("--tbytes", "show sizes in TiB, or TB with --si")

#define HELPINFO_UNITS_SHORT_LONG \
OPTLINE("-b|--raw", "raw numbers in bytes"), \
OPTLINE("-h|--human-readable", "human friendly numbers, base 1024 (default)"), \
OPTLINE("-H", "human friendly numbers, base 1000"), \
OPTLINE("--iec", "use 1024 as a base (KiB, MiB, GiB, TiB)"), \
OPTLINE("--si", "use 1000 as a base (kB, MB, GB, TB)"), \
OPTLINE("-k|--kbytes", "show sizes in KiB, or kB with --si"), \
OPTLINE("-m|--mbytes", "show sizes in MiB, or MB with --si"), \
OPTLINE("-g|--gbytes", "show sizes in GiB, or GB with --si"), \
OPTLINE("-t|--tbytes", "show sizes in TiB, or TB with --si")

#define HELPINFO_OPTION "\x01"
#define HELPINFO_DESC "\x02"
Expand All @@ -84,8 +83,8 @@ struct cmd_group;

#define HELPINFO_INSERT_FORMAT "--format TYPE"

#define HELPINFO_INSERT_VERBOSE "-v|--verbose increase output verbosity"
#define HELPINFO_INSERT_QUIET "-q|--quiet print only errors"
#define HELPINFO_INSERT_VERBOSE OPTLINE("-v|--verbose", "increase output verbosity")
#define HELPINFO_INSERT_QUIET OPTLINE("-q|--quiet", "print only errors")

/*
* Descriptor of output format
Expand Down

0 comments on commit cda1f14

Please sign in to comment.