Skip to content

Commit

Permalink
args: add ARG_NONINTERACTIVE for cmds not supported in lvm shell
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
prajnoha committed Aug 26, 2022
1 parent 800436d commit e6b6a09
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions WHATS_NEW
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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.
Extend VDO and VDOPOOL without flushing and locking fs.
Add --valuesonly option to lvmconfig to print only values without keys.
Expand Down
2 changes: 1 addition & 1 deletion tools/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ arg(replace_ARG, '\0', "replace", pv_VAL, ARG_GROUPABLE, 0,
"Multiple PVs can be replaced by repeating this option.\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"
"the report/output_format setting in \\fBlvm.conf\\fP(5).\n"
"\\fBbasic\\fP is the original format with columns and rows.\n"
Expand Down
1 change: 1 addition & 0 deletions tools/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ static void *dm_pool_alloc(void *p, size_t size)
/* needed to include args.h */
#define ARG_COUNTABLE 0x00000001
#define ARG_GROUPABLE 0x00000002
#define ARG_NONINTERACTIVE 0x00000004
struct cmd_context;
struct arg_values;

Expand Down
9 changes: 9 additions & 0 deletions tools/lvmcmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -2261,6 +2261,15 @@ static int _process_command_line(struct cmd_context *cmd, int *argc, char ***arg

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) {
/*
* Start a new group of arguments:
Expand Down
1 change: 1 addition & 0 deletions tools/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ enum {

#define ARG_COUNTABLE 0x00000001 /* E.g. -vvvv */
#define ARG_GROUPABLE 0x00000002 /* E.g. --addtag */
#define ARG_NONINTERACTIVE 0x00000004 /* only for use in noninteractive mode */

struct arg_values {
unsigned count;
Expand Down

0 comments on commit e6b6a09

Please sign in to comment.