casadm: A generic mechanism to disable commands
Signed-off-by: Michal Mielewczyk <michal.mielewczyk@huawei.com>
This commit is contained in:
parent
dd040386c5
commit
5ef09fb1a2
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright(c) 2012-2021 Intel Corporation
|
||||
* Copyright(c) 2024 Huawei Technologies
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
@ -26,6 +27,11 @@ static int is_command_hidden(const cli_command* commands, int cmd)
|
||||
return commands[cmd].flags & CLI_COMMAND_HIDDEN;
|
||||
}
|
||||
|
||||
static int is_command_blocked(const cli_command* commands, int cmd)
|
||||
{
|
||||
return commands[cmd].flags & CLI_COMMAND_BLOCKED;
|
||||
}
|
||||
|
||||
static void print_short_usage(const app *app_values)
|
||||
{
|
||||
cas_printf(LOG_INFO, "Usage: %s %s\n", app_values->name, app_values->info);
|
||||
@ -313,8 +319,10 @@ void print_help(const app *app_values, const cli_command *commands)
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_command_hidden(commands, i))
|
||||
if (is_command_hidden(commands, i) ||
|
||||
is_command_blocked(commands, i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
get_short_name_string(commands[i].short_name, short_name);
|
||||
|
||||
@ -614,6 +622,11 @@ int args_parse(app *app_values, cli_command *commands, int argc, const char **ar
|
||||
}
|
||||
}
|
||||
|
||||
if (is_command_blocked(commands, i)) {
|
||||
cas_printf(LOG_ERR, "The command is not supported\n");
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
configure_cli_commands(commands);
|
||||
|
||||
if (argc >= 3 && get_help_position(argc, argv) != -1) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright(c) 2012-2021 Intel Corporation
|
||||
* Copyright(c) 2024 Huawei Technologies
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
@ -22,7 +23,8 @@ enum CLI_OPTION_FLAGS {
|
||||
|
||||
enum CLI_COMMAND_FLAGS {
|
||||
CLI_SU_REQUIRED = 1 << 0,
|
||||
CLI_COMMAND_HIDDEN = 1 << 1
|
||||
CLI_COMMAND_HIDDEN = 1 << 1,
|
||||
CLI_COMMAND_BLOCKED = 1 << 2
|
||||
};
|
||||
|
||||
#define ERROR -1
|
||||
|
Loading…
Reference in New Issue
Block a user