Re: [PATCH] bcachefs-tools: add usage function for fs subcommand

Hongbo Li
2024-11-11T02:17:23Z

On 2024/11/10 2:56, Integral wrote:
> Add the missing usage function for "fs" subcommand; when no matching
> subcommand exists, print the usage and return -EINVAL.
>
> Signed-off-by: Integral <integral@archlinuxcn.org>
> ---
> c_src/bcachefs.c | 9 ++++-----
> c_src/cmd_fs.c | 12 ++++++++++++
> c_src/cmds.h | 1 +
> 3 files changed, 17 insertions(+), 5 deletions(-)
>
> diff --git a/c_src/bcachefs.c b/c_src/bcachefs.c
> index 77bf6215..e9e617e1 100644
> --- a/c_src/bcachefs.c
> +++ b/c_src/bcachefs.c
> @@ -113,14 +113,13 @@ int fs_cmds(int argc, char *argv[])
> {
> char *cmd = pop_cmd(&argc, argv);
>
> - if (argc < 1) {
> - bcachefs_usage();
> - exit(EXIT_FAILURE);
> - }
> + if (argc < 1)
> + return fs_usage();
> if (!strcmp(cmd, "usage"))
> return cmd_fs_usage(argc, argv);
>
> - return 0;
> + fs_usage();
Your previous patch also made changes here. Perhaps you could pack them
into a patchset or one patch which would make it more independent.
> + return -EINVAL;
> }
>
> int device_cmds(int argc, char *argv[])
> diff --git a/c_src/cmd_fs.c b/c_src/cmd_fs.c
> index 82eeceff..eb8f7d2e 100644
> --- a/c_src/cmd_fs.c
> +++ b/c_src/cmd_fs.c
> @@ -487,6 +487,18 @@ devs:
> bcache_fs_close(fs);
> }
>
> +int fs_usage(void)
> +{
> + puts("bcachefs fs - manage a running filesystem\n"
> + "Usage: bcachefs fs <CMD> [OPTIONS]\n"
May be the OPTIONS also should be displayed. ie like device_add_usage ...

Thanks,
Hongbo

> + "\n"
> + "Commands:\n"
> + " usage Display detailed filesystem usage\n"
> + "\n"
> + "Report bugs to <linux-bcachefs@vger.kernel.org>");
> + return 0;
> +}
> +
> static void fs_usage_usage(void)
> {
> puts("bcachefs fs usage - display detailed filesystem usage\n"
> diff --git a/c_src/cmds.h b/c_src/cmds.h
> index 64267dc4..99016d52 100644
> --- a/c_src/cmds.h
> +++ b/c_src/cmds.h
> @@ -14,6 +14,7 @@ int cmd_show_super(int argc, char *argv[]);
> int cmd_reset_counters(int argc, char *argv[]);
> int cmd_set_option(int argc, char *argv[]);
>
> +int fs_usage(void);
> int cmd_fs_usage(int argc, char *argv[]);
>
> int device_usage(void);
> --
> 2.47.0
>