Skip to content

Commit

Permalink
build(pyproject): add *2py short commands
Browse files Browse the repository at this point in the history
  • Loading branch information
dbohdan committed Dec 3, 2024
1 parent 89ef0a6 commit 662d11d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Convert between CBOR, JSON, MessagePack, TOML, and YAML.
When installed,
Remarshal provides the command-line command `remarshal`
as well as the short commands
<code>{cbor,json,msgpack,toml,yaml}2<wbr>{cbor,json,msgpack,toml,yaml}</code>.
<code>{cbor,json,msgpack,toml,yaml}2<wbr>{cbor,json,msgpack,py,toml,yaml}</code>.
You can use these commands
to convert between formats,
reformat,
Expand Down Expand Up @@ -182,7 +182,7 @@ options:

Instead of `remarshal` with format arguments,
you can use a short command
<code>{cbor,json,msgpack,toml,yaml}2<wbr>{cbor,json,msgpack,toml,yaml}</code>.
<code>{cbor,json,msgpack,toml,yaml}2<wbr>{cbor,json,msgpack,py,toml,yaml}</code>.
The `remarshal` command and the short commands
exit with status 0 on success,
1 on operational failure,
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,31 @@ remarshal = 'remarshal.main:main'
cbor2cbor = 'remarshal.main:main'
cbor2json = 'remarshal.main:main'
cbor2msgpack = 'remarshal.main:main'
cbor2py = 'remarshal.main:main'
cbor2toml = 'remarshal.main:main'
cbor2yaml = 'remarshal.main:main'
json2cbor = 'remarshal.main:main'
json2json = 'remarshal.main:main'
json2msgpack = 'remarshal.main:main'
json2py = 'remarshal.main:main'
json2toml = 'remarshal.main:main'
json2yaml = 'remarshal.main:main'
msgpack2cbor = 'remarshal.main:main'
msgpack2json = 'remarshal.main:main'
msgpack2msgpack = 'remarshal.main:main'
msgpack2py = 'remarshal.main:main'
msgpack2toml = 'remarshal.main:main'
msgpack2yaml = 'remarshal.main:main'
toml2cbor = 'remarshal.main:main'
toml2json = 'remarshal.main:main'
toml2msgpack = 'remarshal.main:main'
toml2py = 'remarshal.main:main'
toml2toml = 'remarshal.main:main'
toml2yaml = 'remarshal.main:main'
yaml2cbor = 'remarshal.main:main'
yaml2json = 'remarshal.main:main'
yaml2msgpack = 'remarshal.main:main'
yaml2py = 'remarshal.main:main'
yaml2toml = 'remarshal.main:main'
yaml2yaml = 'remarshal.main:main'

Expand Down
8 changes: 7 additions & 1 deletion src/remarshal/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class YAMLOptions(FormatOptions):

INPUT_FORMATS = ["cbor", "json", "msgpack", "toml", "yaml"]
OUTPUT_FORMATS = ["cbor", "json", "msgpack", "python", "toml", "yaml"]
OUTPUT_FORMATS_ARGV0 = ["cbor", "json", "msgpack", "py", "toml", "yaml"]
OPTIONS_CLASSES = {
"cbor": CBOROptions,
"json": JSONOptions,
Expand Down Expand Up @@ -165,9 +166,14 @@ class YAMLOptions(FormatOptions):

def _argv0_to_format(argv0: str) -> tuple[str, str]:
possible_input_format = "(" + "|".join(INPUT_FORMATS) + ")"
possible_output_format = "(" + "|".join(OUTPUT_FORMATS) + ")"
possible_output_format = "(" + "|".join(OUTPUT_FORMATS_ARGV0) + ")"

match = re.search("^" + possible_input_format + "2" + possible_output_format, argv0)
from_, to = match.groups() if match else ("", "")

if to == "py":
to = "python"

return from_, to


Expand Down

0 comments on commit 662d11d

Please sign in to comment.