Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support for multiple input files handling #251

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 20 additions & 19 deletions pywhat/what.py
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