From 6dfbee0a5563da3698ed1de66a803349be326110 Mon Sep 17 00:00:00 2001 From: James McKinney <26463+jpmckinney@users.noreply.github.com> Date: Mon, 15 Jul 2024 23:42:59 -0400 Subject: [PATCH] feat: Correct the usage information for scrapyd command, closes #238 --- docs/news.rst | 1 + scrapyd/__main__.py | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/docs/news.rst b/docs/news.rst index 75581010..cc0801a9 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -20,6 +20,7 @@ Changed - Add a confirmation dialog to the Cancel button. - Add "Last modified" column to the directory listings of log files and item feeds. +- The Scrapyd CLI corrects the usage message and long description, removes all ``twistd`` subcommands, and removes the ``--nodaemon`` and ``--python=`` options, which it overrides. - The Scrapyd CLI runs from the ``scrapyd.__main__`` module instead of from the ``scrapyd.scripts.scrapyd_run`` module. - Drop support for end-of-life Python version 3.7. diff --git a/scrapyd/__main__.py b/scrapyd/__main__.py index a23a6b47..4f846b06 100755 --- a/scrapyd/__main__.py +++ b/scrapyd/__main__.py @@ -2,18 +2,35 @@ import sys from os.path import dirname, join -from twisted.scripts.twistd import run +from twisted.scripts import twistd import scrapyd +class ServerOptions(twistd.ServerOptions): + synopsis = 'Usage: scrapyd [options]' + longdesc = 'Scrapyd is an application for deploying and running Scrapy spiders.' + + def __init__(self): + super().__init__() + # main() always sets -n (--nodaemon) and -y (--python=). + self.longOpt = [opt for opt in self.longOpt if opt not in ('nodaemon', 'python=')] + + @property + def subCommands(self): + return [] # remove alternatives to running txapp.py + + def getUsage(self, width=None): + return super().getUsage(width=width)[:-11] # remove "\nCommands:\n" + + def main(): if len(sys.argv) > 1 and '-v' in sys.argv[1:] or '--version' in sys.argv[1:]: __version__ = pkgutil.get_data(__package__, '../VERSION').decode('ascii').strip() print(f'Scrapyd {__version__}') else: sys.argv[1:1] = ['-n', '-y', join(dirname(scrapyd.__file__), 'txapp.py')] - run() + twistd.app.run(twistd.runApp, ServerOptions) if __name__ == '__main__':