Allow to add key as plain string
Sometimes string is required but current type guessing
is not working with "integer as string" format
MOSSUST-123
Change-Id: I8a99d724caf34d02f2ba85444ddb1fa8ff728946
diff --git a/reclass_tools/cli.py b/reclass_tools/cli.py
index 975b737..b3b0f5a 100644
--- a/reclass_tools/cli.py
+++ b/reclass_tools/cli.py
@@ -43,19 +43,22 @@
def do_add_key(self):
# Try convert to digits
- try:
- add_val = int(self.params.add_value)
- except ValueError:
- # Try convert to float
- try:
- add_val = float(self.params.add_value)
- except ValueError:
+ if self.params.str:
+ add_val = str(self.params.add_value)
+ else:
try:
- # Try convert to list
- if type(eval(self.params.add_value)) == list:
- add_val = eval(self.params.add_value)
- except (SyntaxError, NameError):
- add_val = self.params.add_value
+ add_val = int(self.params.add_value)
+ except ValueError:
+ # Try convert to float
+ try:
+ add_val = float(self.params.add_value)
+ except ValueError:
+ try:
+ # Try convert to list
+ if type(eval(self.params.add_value)) == list:
+ add_val = eval(self.params.add_value)
+ except (SyntaxError, NameError):
+ add_val = self.params.add_value
walk_models.add_reclass_parameter(
self.params.path,
@@ -172,6 +175,12 @@
help='Merge value to list or dict',
default=False)
+ as_str_parser = argparse.ArgumentParser(add_help=False)
+ as_str_parser.add_argument('--str', dest='str',
+ action='store_const', const=True,
+ help='Use value as plain string',
+ default=False)
+
key_parser = argparse.ArgumentParser(add_help=False)
key_parser_help = (
'Key name to find in reclass model files, for example:'
@@ -261,7 +270,7 @@
subparsers.add_parser('add-key',
parents=[key_parser, add_value_parser,
path_parser, verbose_parser,
- merge_parser],
+ merge_parser, as_str_parser],
help="Add a key in YAMLs found in <path>",
description=("Add a key to "
"different YAMLs"))