from __future__ import print_function

import leapp.workflows
import sys
from leapp.exceptions import LeappError, UsageError, CommandError
from leapp.snactor.commands.workflow import workflow
from leapp.utils.clicmd import command_arg, command_opt
from leapp.logger import configure_logger
from leapp.utils.repository import requires_repository, find_repository_basedir
from leapp.repository.scan import find_and_scan_repositories
from leapp.utils.output import report_errors

_LONG_DESCRIPTION = '''
Executes the given workflow.

Using --until-phase the workflow will be only executed until including
the given phase.

Using --until-actor the workflow will be only executed until including
the first occurrence of the given actor name.

For more information please consider reading the documentation at:
https://red.ht/leapp-docs
'''


@workflow.command('run', help='Execute a workflow with the given name', description=_LONG_DESCRIPTION)
@command_arg('name')
@command_opt('until-phase', help='Runs until including the given phase but then exits')
@command_opt('until-actor', help='Runs until including the given actor but then exits')
@requires_repository
def cli(params):
    configure_logger()
    repository = find_and_scan_repositories(find_repository_basedir('.'), include_locals=True)
    try:
        repository.load()
    except LeappError as exc:
        sys.stderr.write(exc.message)
        sys.exit(1)

    wf = repository.lookup_workflow(params.name)
    if not wf:
        raise CommandError('Could not find any workflow named "{}"'.format(params.name))

    instance = wf()
    instance.run(until_phase=params.until_phase, until_actor=params.until_actor)
    report_errors(instance.errors)

@@ -1130,16 +1130,144 @@
 exits')%0A
+@command_opt('--whitelist-experimental', action='append', metavar='ActorName',%0A             help='Enables experimental actors')%0A
 @require
@@ -1712,16 +1712,196 @@
  = wf()%0A
+    for actor_name in params.whitelist_experimental:%0A        actor = repository.lookup_actor(actor_name)%0A        if actor:%0A            instance.whitelist_experimental_actor(actor)%0A
     inst

Support experimental for snactor workflow run