cli: add a generic main 'swh' command and extract the db-init command
in a dedicated submodule. Ensure both:
swh db-init
and
swh-db-init
work.
Related to #1671 (closed).
Migrated from D1426 (view on Phabricator)
Merge request reports
Activity
Build is green See https://jenkins.softwareheritage.org/job/DCORE/job/tox/203/ for more details.
- swh/core/cli/__init__.py 0 → 100644
20 @click.pass_context 21 def swh(ctx, log_level): 22 """Software Heritage Tool 23 """ 24 logger.setLevel(log_level) 25 ctx.ensure_object(dict) 26 ctx.obj['log_level'] = logging._nameToLevel[log_level] 27 28 29 def main(): 30 logging.basicConfig() 31 # load plugins that define cli sub commands 32 for entry_point in pkg_resources.iter_entry_points('swh.cli.subcommands'): 33 cmd = entry_point.load() 34 swh.add_command(cmd, name=entry_point.name) 35 - setup.py 100755 → 100644
51 51 extras_require={'testing': parse_requirements('test')}, 52 52 vcversioner={}, 53 53 include_package_data=True, 54 entry_points={ 55 'console_scripts': ['swh-db-init=swh.core.cli:db_init'], 56 }, 54 entry_points=''' 55 [console_scripts] 56 swh=swh.core.cli:main 57 swh-db-init=swh.core.cli.db:db_init 58 [swh.cli.subcommands] - setup.py 100755 → 100644
51 51 extras_require={'testing': parse_requirements('test')}, 52 52 vcversioner={}, 53 53 include_package_data=True, 54 entry_points={ 55 'console_scripts': ['swh-db-init=swh.core.cli:db_init'], 56 }, 54 entry_points=''' 55 [console_scripts] 56 swh=swh.core.cli:main 57 swh-db-init=swh.core.cli.db:db_init 58 [swh.cli.subcommands] 59 db-init=swh.core.cli.db:db_init So, from what I understand, the subcommand name is set by the name of the function in the plugin, when the swh.command() decorator is called.
I think it would be less surprising, if the entry points were used to actually define which functions are to be decorated, and the subcommand name.
So your entry point definition could be
[swh.cli.subcommands] db-init=swh.core.cli.db:db_init
And you could make the
main
orswh
command lazy-load and decorate the proper function at runtime.Does that make sense?
Build is green See https://jenkins.softwareheritage.org/job/DCORE/job/tox/209/ for more details.
Build is green See https://jenkins.softwareheritage.org/job/DCORE/job/tox/210/ for more details.
mentioned in merge request !57 (closed)
mentioned in merge request swh-deposit!23 (closed)
Some references in the commit message have been migrated:
- T1671 is now #1671 (closed)
Build is green See https://jenkins.softwareheritage.org/job/DCORE/job/tox/212/ for more details.
mentioned in issue swh/meta#1651 (closed)