Skip to content

Commit

Permalink
Reinstate k=v pair handling only for the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
nir0s committed Mar 28, 2018
1 parent 3306940 commit 728a274
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion wryte.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,15 @@ class WryteError(Exception):
pass


def _split_kv(pair):
"""Return dict for key=value.
"""
# TODO: Document that this is costly.
# TODO: Document that it's only split once.
kv = pair.split('=', 1)
return {kv[0]: kv[1]}


if CLI_ENABLED:
CLICK_CONTEXT_SETTINGS = dict(
help_option_names=['-h', '--help'],
Expand Down Expand Up @@ -679,7 +688,18 @@ def main(level, message, objects, pretty, jsonify, name, no_color, simple):
jsonify=jsonify,
color=not no_color,
simple=simple)
getattr(wryter, level.lower())(message, *objects)

objcts = []

# Allows to pass `k=v` pairs.
for obj in objects:
try:
json.loads(obj)
except Exception:
if '=' in obj:
objcts.append(_split_kv(obj))

getattr(wryter, level.lower())(message, *objcts)
else:
def main():
sys.exit(
Expand Down

0 comments on commit 728a274

Please sign in to comment.