Skip to content

Commit 5b33954

Browse files
committed
Option to remove an enclosing key after merge
1 parent 2517d11 commit 5b33954

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

himl/config_generator.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
class ConfigProcessor(object):
2727

28-
def process(self, cwd=None, path=None, filters=(), exclude_keys=(), enclosing_key=None, output_format="yaml",
28+
def process(self, cwd=None, path=None, filters=(), exclude_keys=(), enclosing_key=None, remove_enclosing_key=None, output_format="yaml",
2929
print_data=False, output_file=None, skip_interpolations=False, skip_interpolation_validation=False, skip_secrets=False):
3030

3131
path = self.get_relative_path(path)
@@ -73,7 +73,14 @@ def process(self, cwd=None, path=None, filters=(), exclude_keys=(), enclosing_ke
7373
if not skip_interpolation_validation:
7474
generator.validate_interpolations()
7575

76-
data = generator.add_enclosing_key(enclosing_key) if enclosing_key else generator.generated_data
76+
if enclosing_key:
77+
logger.info("Adding enclosing key {}".format(enclosing_key))
78+
data = generator.add_enclosing_key(enclosing_key)
79+
elif remove_enclosing_key:
80+
logger.info("Removing enclosing key {}".format(remove_enclosing_key))
81+
data = generator.remove_enclosing_key(remove_enclosing_key)
82+
else:
83+
data = generator.generated_data
7784

7885
formatted_data = generator.output_data(data, output_format)
7986

@@ -228,6 +235,9 @@ def output_data(self, data, output_format):
228235
def add_enclosing_key(self, key):
229236
return {key: self.generated_data}
230237

238+
def remove_enclosing_key(self, key):
239+
return self.generated_data[key]
240+
231241
def filter_data(self, keys):
232242
self.generated_data = {key: self.generated_data[key] for key in keys if key in self.generated_data}
233243

himl/main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def do_run(self, opts):
2929
opts.print_data = True
3030

3131
config_processor = ConfigProcessor()
32-
config_processor.process(cwd, opts.path, filters, excluded_keys, opts.enclosing_key, opts.output_format,
33-
opts.print_data, opts.output_file, opts.skip_interpolation_resolving,
32+
config_processor.process(cwd, opts.path, filters, excluded_keys, opts.enclosing_key, opts.remove_enclosing_key,
33+
opts.output_format, opts.print_data, opts.output_file, opts.skip_interpolation_resolving,
3434
opts.skip_interpolation_validation, opts.skip_secrets)
3535

3636
@staticmethod
@@ -57,6 +57,8 @@ def get_parser(parser=None):
5757
help='do not perform any AWS calls to resolve interpolations')
5858
parser.add_argument('--enclosing-key', dest='enclosing_key', type=str,
5959
help='enclose the generated data under a common key')
60+
parser.add_argument('--remove-enclosing-key', dest='remove_enclosing_key', type=str,
61+
help='remove enclosed data from under a common key')
6062
parser.add_argument('--cwd', dest='cwd', type=str, default="",
6163
help='the working directory')
6264
return parser

0 commit comments

Comments
 (0)