Skip to content

Commit

Permalink
Fix error in setup configuration and exit with code 1 if help is CLI …
Browse files Browse the repository at this point in the history
…help is printed
  • Loading branch information
mondeja committed Apr 5, 2021
1 parent c5acbb0 commit dd668e1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.0.19
current_version = 0.0.21

[bumpversion:file:potojson/__init__.py]

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ This output can be customized tuning the parameters of the function:
### CLI

```
usage: potojson [-h] [-v] [-m] [-f] [-p] [-i N] [-l LANGUAGE] [-s PLURAL_FORMS] PO_FILEPATH_OR_CONTENT
usage: potojson [-h] [-v] [-m] [-f] [-p] [-i N] [-l LANGUAGE] [-s PLURAL_FORMS] [-k] [PO_FILEPATH_OR_CONTENT [PO_FILEPATH_OR_CONTENT ...]]
Pofile to JSON conversion without pain.
positional arguments:
PO_FILEPATH_OR_CONTENT
Path to pofile or pofile content as a string. If not provided, will be read from STDIN.
Path to pofile or pofile content as string. If the input file stream is interactive, will be read from STDIN.
optional arguments:
-h, --help show this help message and exit
Expand All @@ -109,12 +109,12 @@ optional arguments:
Use msgid if translation is missing.
-f, --fuzzy Include fuzzy messages.
-p, --pretty Pretty-print JSON output.
-i N, --indent N Number of spaces for indentation used pretty-printing JSON output. Only takes effect passing '--pretty' option.
-i N, --indent N Number of spaces for indentation used pretty-printing JSON output. Only takes effect passing the "--pretty" option.
-l LANGUAGE, --language LANGUAGE
Language for the translations. Will be inserted in the empty key of the JSON output. If not provided and the passed pofile includes the "Language" header, will be extracted from it.
-s PLURAL_FORMS, --plural-forms PLURAL_FORMS
Plural forms for the language of the translations. Will be inserted in the empty key of the JSON output. If not provided and the passed pofile includes the "Plural-Forms" header, will be extracted from it.
-k, --sort-keys Sort JSON output by key.
-k, --sort-keys Sort JSON output by keys.
```

[pypi-link]: https://pypi.org/project/potojson
Expand Down
2 changes: 1 addition & 1 deletion potojson/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import polib


__version__ = "0.0.19"
__version__ = "0.0.21"
__title__ = "potojson"
__description__ = "Pofile to JSON conversion without pain."
__all__ = ("pofile_to_json",)
Expand Down
7 changes: 5 additions & 2 deletions potojson/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _build_parser():
nargs="*",
metavar="PO_FILEPATH_OR_CONTENT",
help="Path to pofile or pofile content as string."
" If not provided, will be read from STDIN.",
" If the input file stream is interactive, will be read from STDIN.",
)
parser.add_argument(
"-m",
Expand Down Expand Up @@ -87,12 +87,15 @@ def _parse_options(args=[]):
parser = _build_parser()
if "-h" in args or "--help" in args:
parser.print_help()
sys.exit(0)
sys.exit(1)
opts = parser.parse_args(args)

if not sys.stdin.isatty():
opts.po_filepath_or_content = sys.stdin.read().strip("\n")
elif isinstance(opts.po_filepath_or_content, list):
if not opts.po_filepath_or_content:
parser.print_help()
sys.exit(1)
opts.po_filepath_or_content = opts.po_filepath_or_content[0]

return opts
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = potojson
version = 0.0.19
version = 0.0.21
description = Pofile to JSON conversion without pain.
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down Expand Up @@ -40,7 +40,7 @@ include_package_data = True

[options.entry_points]
console_scripts =
potojson = potojson.__main__:main
potojson = potojson.__main__:_main

[options.extras_require]
dev =
Expand Down

0 comments on commit dd668e1

Please sign in to comment.