Skip to content

Commit

Permalink
Merge branch 'cli-ocrd-tool-params'
Browse files Browse the repository at this point in the history
  • Loading branch information
kba committed Jun 18, 2018
2 parents 569d4b4 + e9c4510 commit 0e14d05
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions ocrd/cli/ocrd_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,23 @@ def ocrd_tool_tool_dump(ctx):
# ocrd ocrd-tool tool parse-params
# ----------------------------------------------------------------------

@ocrd_tool_tool.command('parse-params', help="Parse parameters with fallback to defaults")
@ocrd_tool_tool.command('parse-params')
@click.option('-p', '--parameters', help='Parameter JSON file', type=click.Path())
@click.option('-j', '--json', help='Output JSON instead of shell variables', is_flag=True, default=False)
@pass_ocrd_tool
def ocrd_tool_tool_parse_params(ctx):
print(json.dumps(ctx.json['tools'][ctx.tool_name], indent=True))
def ocrd_tool_tool_parse_params(ctx, parameters, json):
"""
Parse parameters with fallback to defaults and output as shell-eval'able assignments to params var.
"""
if parameters is None or parameters == "":
parameters = {}
else:
with open(parameters, 'r') as f:
parameters = json.loads(f.read())
parameterValidator = ParameterValidator(ctx.json['tools'][ctx.tool_name])
parameterValidator.validate(parameters)
if json:
print(json.dumps(parameters))
else:
for k in parameters:
print('params["%s"]="%s"' % (k, parameters[k]))

0 comments on commit 0e14d05

Please sign in to comment.