From 9818d279d5ec7b7e43e51a9aa78ca534293258df Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Sat, 3 Aug 2024 16:45:49 +0200 Subject: [PATCH] One letter options --- docs/source/usage.rst | 42 ++++++++++++++++------------ src/jsonyx/tool.py | 65 ++++++++++++++++++++++++++++--------------- 2 files changed, 66 insertions(+), 41 deletions(-) diff --git a/docs/source/usage.rst b/docs/source/usage.rst index dacca9f..8fe2812 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -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 @@ -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. \ No newline at end of file + Allow all JSON deviations. + +.. option:: -t, --trailing-comma + + Add a trailing comma if indented. + +.. option:: -T, --indent-tab + + Indent using tabs. diff --git a/src/jsonyx/tool.py b/src/jsonyx/tool.py index 2e75201..ee5177f 100644 --- a/src/jsonyx/tool.py +++ b/src/jsonyx/tool.py @@ -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", )