From c08bf7636e9ec827dc1b2e6e5d9bb43e311b131f Mon Sep 17 00:00:00 2001 From: "D. Bohdan" Date: Mon, 25 Sep 2023 17:27:57 +0000 Subject: [PATCH] feat(cli): add `-f`/`-t`; hide `-if`/`-of` in help `-f`/`--from` and `-t`/`--to` copy Pandoc and iconv(1). `-if` and `-of` (with a single dash) are legacy options from the Go days of Remarshal. They are long overdue for hiding. --- README.md | 4 ++-- remarshal.py | 20 ++++++++++++++++++-- tests/test_remarshal.py | 4 ++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9a3772a..23575a9 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ options: -v, --version show program's version number and exit -i input, --input input input file - --if {cbor,json,msgpack,toml,yaml}, -if {cbor,json,msgpack,toml,yaml}, --input-format {cbor,json,msgpack,toml,yaml} + --if {cbor,json,msgpack,toml,yaml}, --input-format {cbor,json,msgpack,toml,yaml}, -f {cbor,json,msgpack,toml,yaml}, --from {cbor,json,msgpack,toml,yaml} input format --json-indent n, --indent-json n JSON indentation @@ -84,7 +84,7 @@ options: 1000000, negative for unlimited) -o output, --output output output file - --of {cbor,json,msgpack,toml,yaml}, -of {cbor,json,msgpack,toml,yaml}, --output-format {cbor,json,msgpack,toml,yaml} + --of {cbor,json,msgpack,toml,yaml}, --output-format {cbor,json,msgpack,toml,yaml}, -t {cbor,json,msgpack,toml,yaml}, --to {cbor,json,msgpack,toml,yaml} output format -s, --sort-keys sort JSON, TOML, YAML keys instead of preserving key order diff --git a/remarshal.py b/remarshal.py index 22c6507..a08124e 100755 --- a/remarshal.py +++ b/remarshal.py @@ -118,13 +118,21 @@ def _parse_command_line(argv: List[str]) -> argparse.Namespace: # noqa: C901. if not format_from_argv0: parser.add_argument( "--if", - "-if", "--input-format", + "-f", + "--from", dest="input_format", default="", help="input format", choices=FORMATS, ) + parser.add_argument( + "-if", + dest="input_format", + default="", + help=argparse.SUPPRESS, + choices=FORMATS, + ) if not format_from_argv0 or argv0_to == "json": parser.add_argument( @@ -175,13 +183,21 @@ def _parse_command_line(argv: List[str]) -> argparse.Namespace: # noqa: C901. if not format_from_argv0: parser.add_argument( "--of", - "-of", "--output-format", + "-t", + "--to", dest="output_format", default="", help="output format", choices=FORMATS, ) + parser.add_argument( + "-of", + dest="output_format", + default="", + help=argparse.SUPPRESS, + choices=FORMATS, + ) parser.add_argument( "-p", diff --git a/tests/test_remarshal.py b/tests/test_remarshal.py index 0df8d5b..f210e6f 100755 --- a/tests/test_remarshal.py +++ b/tests/test_remarshal.py @@ -461,9 +461,9 @@ class TestRemarshal(unittest.TestCase): def test_run_no_input_file(self) -> None: argv = [ sys.argv[0], - "-if", + "--from", "json", - "-of", + "--to", "json", "fake-input-file-that-almost-certainly-doesnt-exist-2382", ]