Skip to content

Commit

Permalink
Implement support for multiple input files handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sgaist committed Oct 1, 2022
1 parent 5c36850 commit 8c3e5f7
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions pywhat/what.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def get_text(ctx, opts, value):
ignore_unknown_options=True,
)
)
@click.argument("text_input", callback=get_text, required=False)
@click.argument("text_input", callback=get_text, nargs=-1)
@click.option(
"-t",
"--tags",
Expand Down Expand Up @@ -248,7 +248,7 @@ def main(**kwargs):
* what 'this/is/a/path'
"""
if kwargs["text_input"] is None:
if kwargs["text_input"] == ():
sys.exit("Text input expected. Run 'pywhat --help' for help")
dist = Distribution(
create_filter(kwargs["rarity"], kwargs["include"], kwargs["exclude"])
Expand All @@ -270,25 +270,26 @@ def main(**kwargs):
except ValueError:
print("Invalid key")
sys.exit(1)
identified_output = what_obj.what_is_this(
kwargs["text_input"],
kwargs["only_text"],
key,
kwargs["reverse"],
boundaryless,
kwargs["include_filenames"],
)
for text_input in kwargs["text_input"]:
identified_output = what_obj.what_is_this(
text_input ,
kwargs["only_text"],
key,
kwargs["reverse"],
boundaryless,
kwargs["include_filenames"],
)

p = printer.Printing()
p = printer.Printing()

if kwargs["json"] or str(kwargs["format"]).strip() == "json":
p.print_json(identified_output)
elif str(kwargs["format"]).strip() == "pretty":
p.pretty_print(identified_output, kwargs["text_input"], kwargs["print_tags"])
elif kwargs["format"] is not None:
p.format_print(identified_output, kwargs["format"])
else:
p.print_raw(identified_output, kwargs["text_input"], kwargs["print_tags"])
if kwargs["json"] or str(kwargs["format"]).strip() == "json":
p.print_json(identified_output)
elif str(kwargs["format"]).strip() == "pretty":
p.pretty_print(identified_output, text_input, kwargs["print_tags"])
elif kwargs["format"] is not None:
p.format_print(identified_output, kwargs["format"])
else:
p.print_raw(identified_output, text_input, kwargs["print_tags"])


class What_Object:
Expand Down

0 comments on commit 8c3e5f7

Please sign in to comment.