Skip to content

Commit

Permalink
Display the help message if no file is specified and stdin is a terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
PalmtopTiger authored May 5, 2024
1 parent 472664a commit 0d00c71
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions pysubs2/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ def __call__(self, argv: List[str]) -> int:
return 1

def main(self, argv: List[str]) -> int:
# Dealing with empty arguments
if not argv:
argv = ["--help"]

args = self.parser.parse_args(argv)
errors = 0

Expand Down Expand Up @@ -186,7 +182,7 @@ def main(self, argv: List[str]) -> int:
with open(outpath, "w", encoding=args.output_enc) as outfile:
subs.to_file(outfile, output_format, args.fps, apply_styles=not args.clean,
**extra_output_args)
else:
elif not sys.stdin.isatty():
infile = io.TextIOWrapper(sys.stdin.buffer, args.input_enc)
outfile = io.TextIOWrapper(sys.stdout.buffer, args.output_enc)

Expand All @@ -195,6 +191,9 @@ def main(self, argv: List[str]) -> int:
output_format = args.output_format or subs.format
assert output_format is not None, "output_format must not be None (it's either given or inferred at read time)"
subs.to_file(outfile, output_format, args.fps, apply_styles=not args.clean)
else:
self.parser.print_help()
errors += 1

Check warning on line 196 in pysubs2/cli.py

View check run for this annotation

Codecov / codecov/patch

pysubs2/cli.py#L195-L196

Added lines #L195 - L196 were not covered by tests

return 0 if errors == 0 else 1

Expand Down

0 comments on commit 0d00c71

Please sign in to comment.