Page MenuHomeSoftware Heritage

cli: add a generic main 'swh' command and extract the db-init command

Authored by douardda on Apr 19 2019, 12:13 PM.



in a dedicated submodule. Ensure both:

swh db-init




Related to T1671.

Diff Detail

rDCORE Foundations and core functionalities
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

olasd requested changes to this revision.Apr 19 2019, 4:16 PM
olasd added a subscriber: olasd.
olasd added inline comments.

Do we really need the dict here? If so, would you mind adding a comment as to how/where it's being used in addition to the noqa? (and if not, I guess we can just flip around the for loop)

This revision now requires changes to proceed.Apr 19 2019, 4:16 PM

we probably do not need to keep this dict, but we need to ensure packages are loaded. Let me check this.

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


And you could make the main or swh command lazy-load and decorate the proper function at runtime.

Does that make sense?

swh.cli.subcommands would certainly be more explicit ?


Useless use of swh-? :)

no need to keep the cli plugins in a dict

Implement the entrypoint loading mechanism using functions instead of modules

as suggested by olasd. This does not implement any generic lazy loading
magic stuff for now.

This revision is now accepted and ready to land.May 6 2019, 12:29 PM

include forgotten patch: add log_level to 'swh' context obj

so subcommands can do specific stuff with current log level if needed.

See swh/core/cli/

This revision was landed with ongoing or failed builds.May 6 2019, 3:23 PM
This revision was automatically updated to reflect the committed changes.