From 62470135927bb2460349b822cda815ac515f091f Mon Sep 17 00:00:00 2001 From: dgelessus Date: Sun, 14 Jul 2019 01:23:08 +0200 Subject: [PATCH] Add a setuptools entry point for the command-line interface --- README.rst | 1 + rsrcfork/__main__.py | 6 +++--- setup.cfg | 4 ++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 6a4bdf7..bd1759e 100644 --- a/README.rst +++ b/README.rst @@ -120,6 +120,7 @@ Changelog (next version) ^^^^^^^^^^^^^^ +* Added a setuptools entry point for the command-line interface. This allows calling it using just ``rsrcfork`` instead of ``python3 -m rsrcfork``. * Changed the default value of ``ResourceFork.__init__``'s ``close`` keyword argument from ``True`` to ``False``. This matches the behavior of classes like ``zipfile.ZipFile`` and ``tarfile.TarFile``. * Fixed ``ResourceFork.open`` and ``ResourceFork.__init__`` not closing their streams in some cases. * Refactored the single ``rsrcfork.py`` file into a package. This is an internal change and should have no effect on how the ``rsrcfork`` module is used. diff --git a/rsrcfork/__main__.py b/rsrcfork/__main__.py index 29ef3ca..0f9863c 100644 --- a/rsrcfork/__main__.py +++ b/rsrcfork/__main__.py @@ -160,7 +160,7 @@ def _raw_hexdump(data: bytes): for i in range(0, len(data), 16): print(" ".join(f"{byte:02x}" for byte in data[i:i + 16])) -def main(args: typing.Sequence[str]): +def main(): ap = argparse.ArgumentParser( add_help=False, fromfile_prefix_chars="@", @@ -194,7 +194,7 @@ def main(args: typing.Sequence[str]): ap.add_argument("file", help="The file to read, or - for stdin") ap.add_argument("filter", nargs="*", help="One or more filters to select which resources to display, or omit to show an overview of all resources") - ns = ap.parse_args(args) + ns = ap.parse_args() ns.fork = {"auto": None, "data": False, "rsrc": True}[ns.fork] ns.read_mode = {"auto": None, "stream": False, "seek": True}[ns.read_mode] @@ -348,4 +348,4 @@ def main(args: typing.Sequence[str]): sys.exit(0) if __name__ == "__main__": - main(sys.argv[1:]) + sys.exit(main()) diff --git a/setup.cfg b/setup.cfg index 1630342..2167bc1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -34,3 +34,7 @@ setup_requires = python_requires = >=3.6 packages = rsrcfork + +[options.entry_points] +console_scripts = + rsrcfork = rsrcfork.__main__:main