return 1;
}
-int define_commands(void)
+int define_commands(char *run_name)
{
struct command *cmd;
char line[MAX_LINE];
int prev_was_oo = 0;
int prev_was_op = 0;
int copy_pos = 0;
+ int skip = 0;
+
+ if (run_name && !strcmp(run_name, "help"))
+ run_name = NULL;
create_opt_names_alpha();
cmd->command_index = cmd_count;
cmd_count++;
cmd->name = strdup(name);
+
+ if (run_name && strcmp(run_name, name)) {
+ skip = 1;
+ prev_was_oo_def = 0;
+ prev_was_oo = 0;
+ prev_was_op = 0;
+ continue;
+ }
+ skip = 0;
+
cmd->pos_count = 1;
add_required_line(cmd, line_argc, line_argv);
* context of the existing command[].
*/
- if (is_desc_line(line_argv[0])) {
+ if (is_desc_line(line_argv[0]) && !skip) {
char *desc = strdup(line_orig);
if (cmd->desc) {
int newlen = strlen(cmd->desc) + strlen(desc) + 2;
continue;
}
- if (is_flags_line(line_argv[0])) {
+ if (is_flags_line(line_argv[0]) && !skip) {
add_flags(cmd, line_orig);
continue;
}
- if (is_rule_line(line_argv[0])) {
+ if (is_rule_line(line_argv[0]) && !skip) {
add_rule(cmd, line_orig);
continue;
}
}
/* OO: ... */
- if (is_oo_line(line_argv[0])) {
+ if (is_oo_line(line_argv[0]) && !skip) {
add_optional_opt_line(cmd, line_argc, line_argv);
prev_was_oo_def = 0;
prev_was_oo = 1;
}
/* OP: ... */
- if (is_op_line(line_argv[0])) {
+ if (is_op_line(line_argv[0]) && !skip) {
add_optional_pos_line(cmd, line_argc, line_argv);
prev_was_oo_def = 0;
prev_was_oo = 0;
}
/* IO: ... */
- if (is_io_line(line_argv[0])) {
+ if (is_io_line(line_argv[0]) && !skip) {
add_ignore_opt_line(cmd, line_argc, line_argv);
prev_was_oo = 0;
prev_was_op = 0;
exit(EXIT_FAILURE);
}
- define_commands();
+ define_commands(NULL);
print_man(argv[1], (argc > 2) ? argv[2] : NULL, 1, 1);
int pos_count; /* temp counter used by create-command */
};
-int define_commands(void);
+int define_commands(char *run_name);
int command_id_to_enum(const char *str);
void print_usage(struct command *cmd);
void print_usage_common(struct command_name *cname, struct command *cmd);
void lvm_fin(struct cmd_context *cmd);
struct cmd_context *init_lvm(unsigned set_connections, unsigned set_filters);
-void lvm_register_commands(void);
+void lvm_register_commands(char *name);
int lvm_split(char *str, int *argc, char **argv, int max);
int lvm_run_command(struct cmd_context *cmd, int argc, char **argv);
int lvm_return_code(int ret);
return NULL;
}
-void lvm_register_commands(void)
+void lvm_register_commands(char *name)
{
int i;
* populate commands[] array with command definitions
* by parsing command-lines.in/command-lines-input.h
*/
- if (!define_commands()) {
+ if (!define_commands(name)) {
log_error("Failed to parse command definitions.");
return;
}
int ret, alias = 0;
struct custom_fds custom_fds;
struct cmd_context *cmd;
+ char *name;
if (!argv)
return -1;
cmd->argv = argv;
- lvm_register_commands();
+ if (!alias && argc == 1)
+ name = NULL;
+ else if (alias)
+ name = argv[0];
+ else
+ name = argv[1];
+
+ lvm_register_commands(name);
if (_lvm1_fallback(cmd)) {
/* Attempt to run equivalent LVM1 tool instead */