diff --git a/core/src/zeit/cms/workflow/cli.py b/core/src/zeit/cms/workflow/cli.py index 2f47b7b378..be330bf41f 100644 --- a/core/src/zeit/cms/workflow/cli.py +++ b/core/src/zeit/cms/workflow/cli.py @@ -5,6 +5,7 @@ import transaction import zope.component +from zeit.cms.workflow.interfaces import IManualPublicationOptions, IPublish, IPublishInfo import zeit.cms.celery import zeit.cms.cli @@ -19,7 +20,7 @@ def publish_content(options: dict): we do not want to unregister and reregister the hooks for the application if this function is called inside the regular vivi process """ - options = zeit.cms.workflow.interfaces.IManualPublicationOptions(options) + options = IManualPublicationOptions(options) registry = zope.component.getGlobalSiteManager() # No option, since there is no usecase for re-activating old breaking news @@ -66,7 +67,7 @@ def publish_content(options: dict): log.warn('Skipping %s, not found', uid) continue - info = zeit.cms.workflow.interfaces.IPublishInfo(content) + info = IPublishInfo(content) if not (info.published or options.force_unpublished): log.info('Skipping %s, not published and no --force-unpublished', uid) continue @@ -81,7 +82,7 @@ def publish_content(options: dict): continue try: - zeit.cms.workflow.interfaces.IPublish(content).publish(background=False) + IPublish(content).publish(background=False) transaction.commit() except Exception: transaction.abort() @@ -91,42 +92,17 @@ def publish_content(options: dict): def publish(): parser = argparse.ArgumentParser(description='Publish content') parser.add_argument('--filename', '-f', help='filename with uniqueId per line') - parser.add_argument( - '--force-unpublished', action='store_true', help='Publish even if currently unpublished' - ) - parser.add_argument( - '--force-changed', action='store_true', help='Publish even if with semantic change' - ) - parser.add_argument('--skip-deps', action='store_true', help='Ignore publication dependencies') - - parser.add_argument( - '--use-checkin-hooks', - action='store_true', - help='Notify webhooks after checkin, like contenthub', - ) - parser.add_argument( - '--use-publish-hooks', - action='store_true', - help='Notify webhooks after publish, like contenthub', - ) - parser.add_argument( - '--ignore-services', - default=[], - help=f'Ignore 3rd party services; default: {IGNORE_SERVICES} will be extended by yours;', - nargs='+', - ) - parser.add_argument( - '--wait-tms', action='store_true', help='Have publisher wait for TMS before fastly purge' - ) - parser.add_argument( - '--skip-tms-enrich', - action='store_true', - help='Skip TMS enrich, e.g. checkin already happened', - ) - parser.add_argument( - '--dlps', action='store_true', help='Update date_last_published_semantic timestamp' - ) + for name, field in zope.schema.getFields(IManualPublicationOptions).items(): + arg_name = f'--{name.replace("_", "-")}' + if isinstance(field, zope.schema.Bool): + parser.add_argument(arg_name, action='store_true', help=field.title) + elif isinstance(field, zope.schema.TextLine): + parser.add_argument(arg_name, help=field.title, default=field.default) + elif isinstance(field, zope.schema.Text): + parser.add_argument(arg_name, help=field.title, default=field.default) + else: + parser.add_argument(arg_name, help=field.title) options = parser.parse_args() if not options.filename: @@ -172,13 +148,13 @@ def retract(): log.warn('Skipping %s, not found', id) continue - info = zeit.cms.workflow.interfaces.IPublishInfo(content) + info = IPublishInfo(content) if not (info.published or options.force): log.info('Skipping %s, not published and no --force', id) continue try: - zeit.cms.workflow.interfaces.IPublish(content).retract(background=False) + IPublish(content).retract(background=False) transaction.commit() except Exception: transaction.abort()