@@ -140,26 +140,26 @@ static void handle_help_options_next_level(const struct cmd_struct *cmd,
}
}
-int handle_command_group(const struct cmd_group *grp,
+int handle_command_group(const struct cmd_struct *cmd,
const struct cmd_context *cmdcxt,
int argc, char **argv)
{
- const struct cmd_struct *cmd;
+ const struct cmd_struct *subcmd;
argc--;
argv++;
if (argc < 1) {
- usage_command_group(grp, false, false);
+ usage_command_group(cmd->next, false, false);
exit(1);
}
- cmd = parse_command_token(argv[0], grp);
+ subcmd = parse_command_token(argv[0], cmd->next);
- handle_help_options_next_level(cmd, cmdcxt, argc, argv);
+ handle_help_options_next_level(subcmd, cmdcxt, argc, argv);
- fixup_argv0(argv, cmd->token);
- return cmd_execute(cmd, cmdcxt, argc, argv);
+ fixup_argv0(argv, subcmd->token);
+ return cmd_execute(subcmd, cmdcxt, argc, argv);
}
static const struct cmd_group btrfs_cmd_group;
@@ -943,7 +943,7 @@ static const struct cmd_group balance_cmd_group = {
}
};
-static int cmd_balance(const struct cmd_struct *unused,
+static int cmd_balance(const struct cmd_struct *cmd,
const struct cmd_context *cmdcxt, int argc, char **argv)
{
if (argc == 2 && strcmp("start", argv[1]) != 0) {
@@ -956,7 +956,7 @@ static int cmd_balance(const struct cmd_struct *unused,
return do_balance(argv[1], &args, 0);
}
- return handle_command_group(&balance_cmd_group, cmdcxt, argc, argv);
+ return handle_command_group(cmd, cmdcxt, argc, argv);
}
-DEFINE_GROUP_COMMAND(balance, "balance");
+DEFINE_COMMAND(balance, "balance", cmd_balance, NULL, &balance_cmd_group, 0, 0);
@@ -630,9 +630,4 @@ static const struct cmd_group device_cmd_group = {
}
};
-static int cmd_device(const struct cmd_struct *unused,
- const struct cmd_context *cmdcxt, int argc, char **argv)
-{
- return handle_command_group(&device_cmd_group, cmdcxt, argc, argv);
-}
DEFINE_GROUP_COMMAND_TOKEN(device);
@@ -1242,10 +1242,4 @@ static const struct cmd_group filesystem_cmd_group = {
}
};
-static int cmd_filesystem(const struct cmd_struct *unused,
- const struct cmd_context *cmdcxt,
- int argc, char **argv)
-{
- return handle_command_group(&filesystem_cmd_group, cmdcxt, argc, argv);
-}
DEFINE_GROUP_COMMAND_TOKEN(filesystem);
@@ -658,9 +658,4 @@ static const struct cmd_group inspect_cmd_group = {
}
};
-static int cmd_inspect(const struct cmd_struct *unused,
- const struct cmd_context *cmdcxt, int argc, char **argv)
-{
- return handle_command_group(&inspect_cmd_group, cmdcxt, argc, argv);
-}
DEFINE_GROUP_COMMAND(inspect, "inspect");
@@ -422,10 +422,4 @@ static const struct cmd_group property_cmd_group = {
}
};
-static int cmd_property(const struct cmd_struct *unused,
- const struct cmd_context *cmdcxt,
- int argc, char **argv)
-{
- return handle_command_group(&property_cmd_group, cmdcxt, argc, argv);
-}
DEFINE_GROUP_COMMAND_TOKEN(property);
@@ -558,9 +558,4 @@ static const struct cmd_group qgroup_cmd_group = {
}
};
-static int cmd_qgroup(const struct cmd_struct *unused,
- const struct cmd_context *cmdcxt, int argc, char **argv)
-{
- return handle_command_group(&qgroup_cmd_group, cmdcxt, argc, argv);
-}
DEFINE_GROUP_COMMAND_TOKEN(qgroup);
@@ -219,9 +219,4 @@ static const struct cmd_group quota_cmd_group = {
}
};
-static int cmd_quota(const struct cmd_struct *unused,
- const struct cmd_context *cmdcxt, int argc, char **argv)
-{
- return handle_command_group("a_cmd_group, cmdcxt, argc, argv);
-}
DEFINE_GROUP_COMMAND_TOKEN(quota);
@@ -560,9 +560,4 @@ static const struct cmd_group replace_cmd_group = {
}
};
-static int cmd_replace(const struct cmd_struct *unused,
- const struct cmd_context *cmdcxt, int argc, char **argv)
-{
- return handle_command_group(&replace_cmd_group, cmdcxt, argc, argv);
-}
DEFINE_GROUP_COMMAND_TOKEN(replace);
@@ -273,9 +273,4 @@ static const struct cmd_group rescue_cmd_group = {
}
};
-static int cmd_rescue(const struct cmd_struct *unused,
- const struct cmd_context *cmdcxt, int argc, char **argv)
-{
- return handle_command_group(&rescue_cmd_group, cmdcxt, argc, argv);
-}
DEFINE_GROUP_COMMAND_TOKEN(rescue);
@@ -1807,10 +1807,4 @@ static const struct cmd_group scrub_cmd_group = {
}
};
-static int cmd_scrub(const struct cmd_struct *unused,
- const struct cmd_context *cmdcxt, int argc, char **argv)
-{
- return handle_command_group(&scrub_cmd_group, cmdcxt, argc, argv);
-}
-
DEFINE_GROUP_COMMAND_TOKEN(scrub);
@@ -1466,9 +1466,4 @@ static const struct cmd_group subvolume_cmd_group = {
}
};
-int cmd_subvolume(const struct cmd_struct *unused,
- const struct cmd_context *cmdcxt, int argc, char **argv)
-{
- return handle_command_group(&subvolume_cmd_group, cmdcxt, argc, argv);
-}
DEFINE_GROUP_COMMAND_TOKEN(subvolume);
@@ -107,7 +107,8 @@ struct cmd_struct {
/*
* Define a command for the common case - just a name and string.
* It's assumed that the callback is called cmd_<name> and the usage
- * array is named cmd_<name>_usage.
+ * array is named cmd_<name>_usage. Text is the only supported output
+ * format.
*/
#define DEFINE_SIMPLE_COMMAND(name, token) \
DEFINE_COMMAND(name, token, cmd_ ##name, \
@@ -119,7 +120,7 @@ struct cmd_struct {
* struct cmd_group is called <name>_cmd_group.
*/
#define DEFINE_GROUP_COMMAND(name, token) \
- DEFINE_COMMAND(name, token, cmd_ ##name, \
+ DEFINE_COMMAND(name, token, handle_command_group, \
NULL, &(name ## _cmd_group), 0, 0)
/*
@@ -143,7 +144,7 @@ static inline int cmd_execute(const struct cmd_struct *cmd,
return cmd->fn(cmd, cmdcxt, argc, argv);
}
-int handle_command_group(const struct cmd_group *grp,
+int handle_command_group(const struct cmd_struct *cmd,
const struct cmd_context *cmdcxt,
int argc, char **argv);