1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

args: add ARG_NONINTERACTIVE for cmds not supported in lvm shell

Certain args can't be used in lvm shell ("interactive mode") because
they are not supported there. Add ARG_NONINTERACTIVE flag to mark
such args and error out if we're in interactive mode and at the same
time we detect use of such argument.

Currently, this is the case for --reportformat arg - we don't support
changing the format per command in lvm shell. The whole shell is running
under a reportformat chosen at shell's start.
This commit is contained in:
Peter Rajnoha 2022-08-26 12:17:45 +02:00
parent 800436d2af
commit e6b6a09f90
5 changed files with 13 additions and 1 deletions

View File

@ -1,5 +1,6 @@
Version 2.03.17 - Version 2.03.17 -
=============================== ===============================
Error out in lvm shell if using a cmd argument not supported in the shell.
Fix lvm shell's lastlog command to report previous pre-command failures. Fix lvm shell's lastlog command to report previous pre-command failures.
Extend VDO and VDOPOOL without flushing and locking fs. Extend VDO and VDOPOOL without flushing and locking fs.
Add --valuesonly option to lvmconfig to print only values without keys. Add --valuesonly option to lvmconfig to print only values without keys.

View File

@ -671,7 +671,7 @@ arg(replace_ARG, '\0', "replace", pv_VAL, ARG_GROUPABLE, 0,
"Multiple PVs can be replaced by repeating this option.\n" "Multiple PVs can be replaced by repeating this option.\n"
"See \\fBlvmraid\\fP(7) for more information.\n") "See \\fBlvmraid\\fP(7) for more information.\n")
arg(reportformat_ARG, '\0', "reportformat", reportformat_VAL, 0, 0, arg(reportformat_ARG, '\0', "reportformat", reportformat_VAL, ARG_NONINTERACTIVE, 0,
"Overrides current output format for reports which is defined globally by\n" "Overrides current output format for reports which is defined globally by\n"
"the report/output_format setting in \\fBlvm.conf\\fP(5).\n" "the report/output_format setting in \\fBlvm.conf\\fP(5).\n"
"\\fBbasic\\fP is the original format with columns and rows.\n" "\\fBbasic\\fP is the original format with columns and rows.\n"

View File

@ -78,6 +78,7 @@ static void *dm_pool_alloc(void *p, size_t size)
/* needed to include args.h */ /* needed to include args.h */
#define ARG_COUNTABLE 0x00000001 #define ARG_COUNTABLE 0x00000001
#define ARG_GROUPABLE 0x00000002 #define ARG_GROUPABLE 0x00000002
#define ARG_NONINTERACTIVE 0x00000004
struct cmd_context; struct cmd_context;
struct arg_values; struct arg_values;

View File

@ -2261,6 +2261,15 @@ static int _process_command_line(struct cmd_context *cmd, int *argc, char ***arg
av = &cmd->opt_arg_values[arg_enum]; av = &cmd->opt_arg_values[arg_enum];
if (a->flags & ARG_NONINTERACTIVE && cmd->is_interactive) {
log_error("Argument%s%c%s%s cannot be used in interactive mode.",
a->short_opt ? " -" : "",
a->short_opt ? : ' ',
(a->short_opt && a->long_opt) ?
"/" : "", a->long_opt ? : "");
return 0;
}
if (a->flags & ARG_GROUPABLE) { if (a->flags & ARG_GROUPABLE) {
/* /*
* Start a new group of arguments: * Start a new group of arguments:

View File

@ -96,6 +96,7 @@ enum {
#define ARG_COUNTABLE 0x00000001 /* E.g. -vvvv */ #define ARG_COUNTABLE 0x00000001 /* E.g. -vvvv */
#define ARG_GROUPABLE 0x00000002 /* E.g. --addtag */ #define ARG_GROUPABLE 0x00000002 /* E.g. --addtag */
#define ARG_NONINTERACTIVE 0x00000004 /* only for use in noninteractive mode */
struct arg_values { struct arg_values {
unsigned count; unsigned count;