mirror of
https://github.com/ansible/awx.git
synced 2026-03-05 02:31:03 -03:30
cli: add support for loading JSON/YAML w/ the ansible-like @ syntax
This commit is contained in:
@@ -80,6 +80,8 @@ class ResourceOptionsParser(object):
|
||||
continue
|
||||
|
||||
def json_or_yaml(v):
|
||||
if v.startswith('@'):
|
||||
v = open(v[1:]).read()
|
||||
try:
|
||||
return json.loads(v)
|
||||
except Exception:
|
||||
@@ -124,6 +126,15 @@ class ResourceOptionsParser(object):
|
||||
if param['type'] == 'id' and not kwargs.get('help'):
|
||||
kwargs['help'] = 'the ID of the associated {}'.format(k)
|
||||
|
||||
if param['type'] == 'json' and method != 'list':
|
||||
help_parts = []
|
||||
if kwargs.get('help'):
|
||||
help_parts.append(kwargs['help'])
|
||||
else:
|
||||
help_parts.append('a JSON or YAML string.')
|
||||
help_parts.append('You can optionally specify a file path e.g., @path/to/file.yml')
|
||||
kwargs['help'] = ' '.join(help_parts)
|
||||
|
||||
# SPECIAL CUSTOM LOGIC GOES HERE :'(
|
||||
# There are certain requirements that aren't captured well by our
|
||||
# HTTP OPTIONS due to $reasons
|
||||
|
||||
Reference in New Issue
Block a user