aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-06-10 20:59:22 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-06-10 20:59:22 -0400
commit7a66cf70c5d8b02f84595e5648c12e7422e4d03e (patch)
treef5cee45b013544f92073246ecf845e53ae2bfa15
parentf43c9702e002db5466916a7c9b619f7ec150da7c (diff)
downloadbcachefs-tools-7a66cf70c5d8b02f84595e5648c12e7422e4d03e.tar.gz
cmd_fs_usage: Implement --help
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--bcachefs.c6
-rw-r--r--cmd_fs.c32
-rw-r--r--cmds.h1
3 files changed, 25 insertions, 14 deletions
diff --git a/bcachefs.c b/bcachefs.c
index 8616d554..a3fe6d82 100644
--- a/bcachefs.c
+++ b/bcachefs.c
@@ -113,8 +113,10 @@ static int fs_cmds(int argc, char *argv[])
{
char *cmd = pop_cmd(&argc, argv);
- if (argc < 1)
- return fs_usage();
+ if (argc < 1) {
+ usage();
+ exit(EXIT_FAILURE);
+ }
if (!strcmp(cmd, "usage"))
return cmd_fs_usage(argc, argv);
diff --git a/cmd_fs.c b/cmd_fs.c
index 007c8d87..d6e2b223 100644
--- a/cmd_fs.c
+++ b/cmd_fs.c
@@ -1,4 +1,4 @@
-
+#include <getopt.h>
#include <stdio.h>
#include <sys/ioctl.h>
@@ -275,30 +275,40 @@ static void fs_usage_to_text(struct printbuf *out, const char *path)
bcache_fs_close(fs);
}
-int fs_usage(void)
+static void fs_usage_usage(void)
{
- puts("bcachefs fs - manage a running filesystem\n"
- "Usage: bcachefs fs <CMD> [OPTION]... path\n"
- "\n"
- "Commands:\n"
- " usage show disk usage\n"
- "\n"
- "Report bugs to <linux-bcachefs@vger.kernel.org>");
- return 0;
+ puts("bcachefs fs usage - display detailed filesystem usage\n"
+ "Usage: bcachefs fs usage [OPTION]... <mountpoint>\n"
+ "\n"
+ "Options:\n"
+ " -h, --human-readable Human readable units\n"
+ " --help Display this help and exit\n"
+ "Report bugs to <linux-bcachefs@vger.kernel.org>");
}
int cmd_fs_usage(int argc, char *argv[])
{
+ static const struct option longopts[] = {
+ { "help", no_argument, NULL, 'H' },
+ { NULL }
+ };
bool human_readable = false;
struct printbuf buf = PRINTBUF;
char *fs;
int opt;
- while ((opt = getopt(argc, argv, "h")) != -1)
+ while ((opt = getopt_long(argc, argv, "h",
+ longopts, NULL)) != -1)
switch (opt) {
case 'h':
human_readable = true;
break;
+ case 'H':
+ fs_usage_usage();
+ exit(EXIT_SUCCESS);
+ default:
+ fs_usage_usage();
+ exit(EXIT_FAILURE);
}
args_shift(optind);
diff --git a/cmds.h b/cmds.h
index 440b1966..96216b21 100644
--- a/cmds.h
+++ b/cmds.h
@@ -20,7 +20,6 @@ int cmd_run(int argc, char *argv[]);
int cmd_stop(int argc, char *argv[]);
#endif
-int fs_usage(void);
int cmd_fs_usage(int argc, char *argv[]);
int device_usage(void);