summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPeter Rajnoha <prajnoha@redhat.com>2022-08-16 16:56:06 +0200
committerPeter Rajnoha <prajnoha@redhat.com>2022-08-17 10:47:24 +0200
commitb4cc28c2ef72ee022c1a03819927e31775c18676 (patch)
tree2d027a817b5a26e53ce32e97dd8cdb9f835568af /tools
parent81839cc4ebf566ea9f3e6d819c7338b98cdec374 (diff)
downloadlvm2-b4cc28c2ef72ee022c1a03819927e31775c18676.tar.gz
lvmconfig: add --valuesonly option
The new --valuesonly option causes the lvmconfig output to contain only values without keys for each config node. This is practical mainly in case where we use lvmconfig in scripts and we want to assign the value to a different custom key or simply output the value itself without the key. For example: # lvmconfig --type full activation/raid_fault_policy raid_fault_policy="warn" # lvmconfig --type full activation/raid_fault_policy --valuesonly "warn" # my_var=$(lvmconfig --type full activation/raid_fault_policy --valuesonly) # echo $my_var "warn"
Diffstat (limited to 'tools')
-rw-r--r--tools/args.h3
-rw-r--r--tools/command-lines.in5
-rw-r--r--tools/dumpconfig.c7
3 files changed, 13 insertions, 2 deletions
diff --git a/tools/args.h b/tools/args.h
index 9229b8764..bdeefca7d 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -905,6 +905,9 @@ arg(validate_ARG, '\0', "validate", 0, 0, 0,
"merged configuration tree, also use --mergedconfig.\n"
"The validation is done even if \\fBlvm.conf\\fP(5) \\fBconfig/checks\\fP is disabled.\n")
+arg(valuesonly_ARG, '\0', "valuesonly", 0, 0, 0,
+ "When printing config settings, print only values without keys.\n")
+
arg(vdo_ARG, '\0', "vdo", 0, 0, 0,
"Specifies the command is handling VDO LV.\n"
"See --type vdo.\n"
diff --git a/tools/command-lines.in b/tools/command-lines.in
index b6a03d158..6e9e7bdea 100644
--- a/tools/command-lines.in
+++ b/tools/command-lines.in
@@ -221,8 +221,9 @@ OO_REPORT: --aligned, --all, --binary, --configreport ConfigReport, --foreign,
#
OO_CONFIG: --atversion String, --typeconfig ConfigType, --file String, --ignoreadvanced,
--ignoreunsupported, --ignorelocal, --list, --mergedconfig, --metadataprofile String,
---sinceversion String, --showdeprecated, --showunsupported, --validate, --withsummary,
---withcomments, --withgeneralpreamble, --withlocalpreamble, --withspaces, --unconfigured, --withversions
+--sinceversion String, --showdeprecated, --showunsupported, --validate, --valuesonly,
+--withsummary, --withcomments, --withgeneralpreamble, --withlocalpreamble, --withspaces,
+--unconfigured, --withversions
---
diff --git a/tools/dumpconfig.c b/tools/dumpconfig.c
index 9e4408e16..4a0f193c4 100644
--- a/tools/dumpconfig.c
+++ b/tools/dumpconfig.c
@@ -242,6 +242,10 @@ int dumpconfig(struct cmd_context *cmd, int argc, char **argv)
log_error("--withgeneralpreamble has no effect with --type list");
return EINVALID_CMD_LINE;
}
+ if (arg_is_set(cmd, valuesonly_ARG)) {
+ log_err("--valuesonly has no effect with --type list");
+ return EINVALID_CMD_LINE;
+ }
/* list type does not require status check */
} else if (!strcmp(type, "full")) {
tree_spec.type = CFG_DEF_TREE_FULL;
@@ -320,6 +324,9 @@ int dumpconfig(struct cmd_context *cmd, int argc, char **argv)
if (arg_is_set(cmd, withspaces_ARG))
tree_spec.withspaces = 1;
+ if (arg_is_set(cmd, valuesonly_ARG))
+ tree_spec.valuesonly = 1;
+
if (cft_check_handle)
tree_spec.check_status = cft_check_handle->status;