Skip to content

Commit

Permalink
One letter options
Browse files Browse the repository at this point in the history
  • Loading branch information
nineteendo committed Aug 3, 2024
1 parent d194d58 commit 9818d27
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 41 deletions.
42 changes: 24 additions & 18 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ Command Line Interface
The :mod:`jsonyx` module provides a simple command line interface to
validate and pretty-print JSON objects.

If the optional ``filename`` argument is not specified, :data:`sys.stdin` will
If the optional ``filename`` argument is not specified, :data:`sys.stdin` will
be used:

.. code-block:: shell-session
Expand Down Expand Up @@ -259,34 +259,40 @@ Command line options

.. option:: -h, --help

Show the help message and exit.
Show the help message and exit.

.. option:: --compact
.. option:: -a, --ensure-ascii

Don't add unnecessary whitespace after "," and ":".
Escape non-ascii characters.

.. option:: --ensure-ascii
.. option:: -c, --compact

Escape non-ascii characters.
Don't add unnecessary whitespace after "," and ":".

.. option:: --indent
--indent-tab
.. option:: -C, --no-commas

Mutually exclusive options for whitespace control.
Separate items by whitespace instead of comma's.

.. option:: --no-commas
--trailing-comma
.. option:: -d, --use-decimal

Mutually exclusive options for comma control.
Use decimal instead of float.

.. option:: --nonstrict
.. option:: -i SPACES, --indent SPACES

Allow all JSON deviations.
Indent using spaces.

.. option:: --sort-keys
.. option:: -s, --sort-keys

Sort the keys of objects.
Sort the keys of objects.

.. option:: --use-decimal
.. option:: -S, --nonstrict

Use decimal instead of float.
Allow all JSON deviations.

.. option:: -t, --trailing-comma

Add a trailing comma if indented.

.. option:: -T, --indent-tab

Indent using tabs.
65 changes: 42 additions & 23 deletions src/jsonyx/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,44 +43,63 @@ def register(parser: ArgumentParser) -> None:
help="the JSON file to be validated or pretty-printed",
)
parser.add_argument(
"--compact",
action="store_true",
help='don\'t add unnecessary whitespace after "," and ":"',
)
parser.add_argument(
"-a",
"--ensure-ascii",
action="store_true",
help="escape non-ascii characters",
)
group = parser.add_mutually_exclusive_group()
group.add_argument(
"--indent", type=int, metavar="SPACES", help="indent using spaces",
)
group.add_argument(
"--indent-tab", action="store_const", const="\t", dest="indent",
help="indent using tabs",
parser.add_argument(
"-c",
"--compact",
action="store_true",
help='don\'t add unnecessary whitespace after "," and ":"',
)
group2 = parser.add_mutually_exclusive_group()
group2.add_argument(
comma_group = parser.add_mutually_exclusive_group()
comma_group.add_argument(
"-C",
"--no-commas",
action="store_true",
help="separate items by whitespace",
help="separate items by whitespace instead of comma's",
)
group2.add_argument(
"--trailing-comma",
parser.add_argument(
"-d",
"--use-decimal",
action="store_true",
help="add a trailing comma if indented",
help="use decimal instead of float",
)
parser.add_argument(
"--nonstrict", action="store_true", help="allow all JSON deviations",
indent_group = parser.add_mutually_exclusive_group()
indent_group.add_argument(
"-i",
"--indent",
type=int,
metavar="SPACES",
help="indent using spaces",
)
parser.add_argument(
"--sort-keys", action="store_true", help="sort the keys of objects",
"-s",
"--sort-keys",
action="store_true",
help="sort the keys of objects",
)
parser.add_argument(
"--use-decimal",
"-S",
"--nonstrict",
action="store_true",
help="use decimal instead of float",
help="allow all JSON deviations",
)
comma_group.add_argument(
"-t",
"--trailing-comma",
action="store_true",
help="add a trailing comma if indented",
)
indent_group.add_argument(
"-T",
"--indent-tab",
action="store_const",
const="\t",
dest="indent",
help="indent using tabs",
)


Expand Down

0 comments on commit 9818d27

Please sign in to comment.