Skip to content

Commit

Permalink
casadm: A generic mechanism to disable commands
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Mielewczyk <michal.mielewczyk@huawei.com>
  • Loading branch information
mmichal10 committed Sep 6, 2024
1 parent dd04038 commit 5ef09fb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 14 additions & 1 deletion casadm/argp.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright(c) 2012-2021 Intel Corporation
* Copyright(c) 2024 Huawei Technologies
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion casadm/argp.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright(c) 2012-2021 Intel Corporation
* Copyright(c) 2024 Huawei Technologies
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand All @@ -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
Expand Down

0 comments on commit 5ef09fb

Please sign in to comment.