[mod] main:args:template_path
This commit is contained in:
parent
207a2b2a89
commit
75dcafc58c
|
|
@ -72,9 +72,7 @@ def handle_value(
|
|||
)
|
||||
return (
|
||||
file_read(value[len(options["indicator"]):])
|
||||
if
|
||||
value.startswith(options["indicator"])
|
||||
else
|
||||
if value.startswith(options["indicator"]) else
|
||||
value
|
||||
)
|
||||
|
||||
|
|
@ -91,9 +89,7 @@ def data_from_file(
|
|||
(
|
||||
lambda content: (
|
||||
_json.loads(content)
|
||||
if
|
||||
path.endswith(".json")
|
||||
else
|
||||
if path.endswith(".json") else
|
||||
_yaml.safe_load(content)
|
||||
)
|
||||
) (file_read(path))
|
||||
|
|
@ -101,7 +97,7 @@ def data_from_file(
|
|||
)
|
||||
|
||||
|
||||
def data_from_arguments(
|
||||
def data_from_adhoc_arguments(
|
||||
arguments
|
||||
):
|
||||
return dict(
|
||||
|
|
@ -125,7 +121,16 @@ def main(
|
|||
argument_parser = _argparse.ArgumentParser(
|
||||
prog = "coin",
|
||||
formatter_class = _argparse.ArgumentDefaultsHelpFormatter,
|
||||
description = "transforms an input string (stdin) by processing its placeholders; example: »echo '{{flowers}} are {{color}}' | coin -a flowers:roses -a color:red«",
|
||||
description = "transforms a template string to its refined version by substituting its placeholders with concrete values; example: »echo '{{flowers}} are {{color}}' | coin -a flowers:roses -a color:red«",
|
||||
)
|
||||
argument_parser.add_argument(
|
||||
"-t",
|
||||
"--template-path",
|
||||
dest = "template_path",
|
||||
type = str,
|
||||
metavar = "<template-path>",
|
||||
default = None,
|
||||
help = "default: read from stdin",
|
||||
)
|
||||
argument_parser.add_argument(
|
||||
"-d",
|
||||
|
|
@ -137,12 +142,11 @@ def main(
|
|||
)
|
||||
argument_parser.add_argument(
|
||||
"-a",
|
||||
"--argument",
|
||||
"--adhoc-argument",
|
||||
type = str,
|
||||
dest = "arguments",
|
||||
dest = "adhoc_arguments",
|
||||
action = "append",
|
||||
default = None,
|
||||
metavar = "<key>:<value>",
|
||||
metavar = "<adhoc-argument-key>:<adhoc-argument-value>",
|
||||
help = "prefixing <value> with '@' causes the value to be interpreted as the path to a text file, whose content shall be used",
|
||||
)
|
||||
argument_parser.add_argument(
|
||||
|
|
@ -170,11 +174,15 @@ def main(
|
|||
args = argument_parser.parse_args()
|
||||
|
||||
## exec
|
||||
content_in = _sys.stdin.read()
|
||||
content_in = (
|
||||
_sys.stdin.read()
|
||||
if (args.template_path is None) else
|
||||
file_read(args.template_path)
|
||||
)
|
||||
data = (
|
||||
data_from_file(args.data_path)
|
||||
|
|
||||
data_from_arguments(args.arguments)
|
||||
data_from_adhoc_arguments(args.adhoc_arguments)
|
||||
)
|
||||
content_out = string_coin(
|
||||
content_in,
|
||||
|
|
|
|||
Loading…
Reference in a new issue