Skip to content

Commit

Permalink
Merge pull request #45 from deepmind/inv-pattern-filter
Browse files Browse the repository at this point in the history
Added --pattern feature to inventory cli
  • Loading branch information
ramaro authored Mar 23, 2018
2 parents b0a1c67 + ed7ca72 commit a398c97
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion kapitan/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import traceback
import yaml

from kapitan.utils import jsonnet_file, PrettyDumper, flatten_dict, searchvar
from kapitan.utils import jsonnet_file, PrettyDumper, flatten_dict, searchvar, deep_get
from kapitan.targets import compile_targets
from kapitan.resources import search_imports, resource_callbacks, inventory_reclass
from kapitan.version import PROJECT_NAME, DESCRIPTION, VERSION
Expand Down Expand Up @@ -91,6 +91,8 @@ def main():
help='set inventory path, default is "./inventory"')
inventory_parser.add_argument('--flat', '-F', help='flatten nested inventory variables',
action='store_true', default=False)
inventory_parser.add_argument('--pattern', '-p', default='',
help='filter pattern (e.g. parameters.mysql), default is ""')

searchvar_parser = subparser.add_parser('searchvar',
help='show all inventory files where var is declared')
Expand Down Expand Up @@ -179,6 +181,9 @@ def main():
inv = inventory_reclass(args.inventory_path)
if args.target_name != '':
inv = inv['nodes'][args.target_name]
if args.pattern != '':
pattern = args.pattern.split(".")
inv = deep_get(inv, pattern)
if args.flat:
inv = flatten_dict(inv)
yaml.dump(inv, sys.stdout, width=10000)
Expand Down
2 changes: 1 addition & 1 deletion kapitan/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"Project description variables"

PROJECT_NAME = 'kapitan'
VERSION = '0.12.0'
VERSION = '0.13.0'
DESCRIPTION = ('Generic templated configuration management for Kubernetes,'
'Terraform and other things')
AUTHOR = 'Ricardo Amaro'
Expand Down

0 comments on commit a398c97

Please sign in to comment.