Skip to contentSkip to conversation

master - lvmconfig: add --withspaces option

PATCH Peter Rajnoha 1 participant 1 message Jun 24, 2015

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=a4724350e4909dd1b74231f22c41434dbe02c14d
Commit:        a4724350e4909dd1b74231f22c41434dbe02c14d
Parent:        a25d92c88b034996667da3764ac5b1de15448174
Author:        Peter Rajnoha <[email protected]>
AuthorDate:    Wed Jun 24 13:14:30 2015 +0200
Committer:     Peter Rajnoha <[email protected]>
CommitterDate: Wed Jun 24 13:19:23 2015 +0200

lvmconfig: add --withspaces option

We shouldn't be adding spaces by default in output as that may be be used already in scripts and especially for the eval in shell scripts where spaces are not allowed between key and value!

Add --withspaces option to lvmconfig for pretty output with more space in for readability.

---
 WHATS_NEW           |    1 +
 lib/config/config.c |    8 +++++---
 lib/config/config.h |    1 +
 man/lvmconfig.8.in  |    5 +++++
 tools/args.h        |    1 +
 tools/commands.h    |    3 ++-
 tools/dumpconfig.c  |    3 +++
 7 files changed, 18 insertions(+), 4 deletions(-)
WHATS_NEW +1 -0
index 7da2b51..94766af 100644
@@ -1,5 +1,6 @@
 Version 2.02.123 - 
 =================================
+  Add --withspaces to lvmconfig to add spaces in output for better readability.
 
 Version 2.02.122 - 20th June 2015
 =================================
lib/config/config.c +5 -3
index 6f9d413..22b8f09 100644
@@ -1756,7 +1756,8 @@ static struct dm_config_node *_add_def_node(struct dm_config_tree *cft,
 			log_error("Failed to create default config setting node value.");
 			return NULL;
 		}
-		format_flags |= DM_CONFIG_VALUE_FMT_COMMON_EXTRA_SPACES;
+		if (spec->withspaces)
+			format_flags |= DM_CONFIG_VALUE_FMT_COMMON_EXTRA_SPACES;
 	}
 
 	cn->id = def->id;
@@ -1799,8 +1800,9 @@ static struct dm_config_node *_add_def_node(struct dm_config_tree *cft,
 		}
 		dm_config_value_set_format_flags(cn->v, format_flags);
 	} else {
-		format_flags |= (DM_CONFIG_VALUE_FMT_COMMON_ARRAY |
-				 DM_CONFIG_VALUE_FMT_COMMON_EXTRA_SPACES);
+		if (spec->withspaces)
+			format_flags |= DM_CONFIG_VALUE_FMT_COMMON_EXTRA_SPACES;
+		format_flags |= DM_CONFIG_VALUE_FMT_COMMON_ARRAY;
 		cn->v = _get_def_array_values(cft, def, format_flags);
 	}
 
lib/config/config.h +1 -0
index b03ad6b..9601dc1 100644
@@ -163,6 +163,7 @@ struct config_def_tree_spec {
 	unsigned withsummary:1;		/* include first line of comments - a summary */
 	unsigned withcomments:1;	/* include all comment lines */
 	unsigned withversions:1;	/* include versions */
+	unsigned withspaces:1;		/* add more spaces in output for better readability */
 	unsigned unconfigured:1;	/* use unconfigured path strings */
 	uint8_t *check_status;		/* status of last tree check (currently needed for CFG_DEF_TREE_MISSING only) */
 };
man/lvmconfig.8.in +5 -0
index 4e61280..761b1e9 100644
@@ -27,6 +27,7 @@ lvmconfig, lvm dumpconfig, lvm config \(em Display LVM configuration
 .RB [ \-\-validate ]
 .RB [ \-\-withsummary ]
 .RB [ \-\-withcomments ]
+.RB [ \-\-withspaces ]
 .RB [ \-\-withversions ]
 .RB [ ConfigurationNode... ]
 
@@ -186,6 +187,10 @@ Display a full comment for each configuration node. For deprecated
 settings, also display comments about deprecation in addition.
 
 .TP
+.B \-\-withspaces
+Where appropriate, add more spaces in output for better readability.
+
+.TP
 .B \-\-withversions
 Also display a comment containing the version of introduction for
 each configuration node. If the setting is deprecated, also display
tools/args.h +1 -0
index b5c4243..7f7667d 100644
@@ -124,6 +124,7 @@ arg(vgmetadatacopies_ARG, '\0', "vgmetadatacopies", metadatacopies_arg, 0)
 arg(virtualoriginsize_ARG, '\0', "virtualoriginsize", size_mb_arg, 0)
 arg(withsummary_ARG, '\0', "withsummary", NULL, 0)
 arg(withcomments_ARG, '\0', "withcomments", NULL, 0)
+arg(withspaces_ARG, '\0', "withspaces", NULL, 0)
 arg(withversions_ARG, '\0', "withversions", NULL, 0)
 arg(writebehind_ARG, '\0', "writebehind", int_arg, 0)
 arg(writemostly_ARG, '\0', "writemostly", string_arg, ARG_GROUPABLE)
tools/commands.h +2 -1
index 8e87681..9403951 100644
@@ -104,13 +104,14 @@ xx(dumpconfig,
    "\t[--validate]\n"
    "\t[--withsummary]\n"
    "\t[--withcomments]\n"
+   "\t[--withspaces]\n"
    "\t[--unconfigured]\n"
    "\t[--withversions]\n"
    "\t[ConfigurationNode...]\n",
    atversion_ARG, configtype_ARG, file_ARG, ignoreadvanced_ARG,
    ignoreunsupported_ARG, ignorelocal_ARG, list_ARG, mergedconfig_ARG, metadataprofile_ARG,
    showdeprecated_ARG, showunsupported_ARG, validate_ARG, withsummary_ARG, withcomments_ARG,
-   unconfigured_ARG, withversions_ARG)
+   withspaces_ARG, unconfigured_ARG, withversions_ARG)
 
 xx(formats,
    "List available metadata formats",
tools/dumpconfig.c +3 -0
index 97de57a..f6a6217 100644
@@ -277,6 +277,9 @@ int dumpconfig(struct cmd_context *cmd, int argc, char **argv)
 	if (arg_count(cmd, withversions_ARG))
 		tree_spec.withversions = 1;
 
+	if (arg_count(cmd, withspaces_ARG))
+		tree_spec.withspaces = 1;
+
 	if (cft_check_handle)
 		tree_spec.check_status = cft_check_handle->status;