<commit_before>import sys

from botocore.exceptions import ClientError

from caravan.swf import get_swf_connection, is_response_success
from caravan.commands import BaseCommand


class Command(BaseCommand):

    description = 'Start a workflow execution'

    def setup_arguments(self, parser):
        parser.add_argument('-d', '--domain', required=True)
        parser.add_argument('-i', '--id', required=True)
        parser.add_argument('-n', '--name', required=True)
        parser.add_argument('-v', '--version', required=True)
        parser.add_argument('-t', '--task-list', required=True)

        parser.add_argument(
            '--input',
            help='Raw input data for this execution',
            metavar='"<Some data>"')
        parser.add_argument(
            '--tag-list',
            help='List of tags to associate with the workflow execution',
            metavar='"tag1 tag2 ..."')
        parser.add_argument(
            '--execution-timeout',
            help='The maximum total duration for this workflow execution (seconds)')
        parser.add_argument(
            '--task-timeout',
            help='The maximum duration of decision tasks (seconds)')
        parser.add_argument(
            '--child-policy',
            help='Policy to use for the child executions of this execution')
        parser.add_argument(
            '--lambda-role',
            help='ARN of an IAM role that authorizes SWF to invoke Lambda functions')

    def run(self):
        connection = get_swf_connection()

        callargs = {
            'taskList': {'name': self.args.task_list},
            }

        if self.args.input:
            callargs['input'] = self.args.input
        if self.args.tag_list:
            callargs['tagList'] = self.args.tag_list.split()
        if self.args.execution_timeout:
            callargs['executionStartToCloseTimeout'] = self.args.execution_timeout
        if self.args.task_timeout:
            callargs['taskStartToCloseTimeout'] = self.args.task_timeout
        if self.args.child_policy:
            callargs['childPolicy'] = self.args.child_policy
        if self.args.lambda_role:
            callargs['lambdaRole'] = self.args.lambda_role

        try:
            response = connection.start_workflow_execution(
                domain=self.args.domain,
                workflowId=self.args.id,
                workflowType={
                    'name': self.args.name,
                    'version': self.args.version
                    },
                **callargs)
        except ClientError as err:
            sys.exit(err)
        else:
            if is_response_success(response):
                print 'Workflow execution successfully created as RunId %s' % (
                    response['runId'])
            else:
                sys.exit('Error: %s' % response)<commit_msg>Start argument --task-list must be optional<commit_after>import sys

from botocore.exceptions import ClientError

from caravan.swf import get_swf_connection, is_response_success
from caravan.commands import BaseCommand


class Command(BaseCommand):

    description = 'Start a workflow execution'

    def setup_arguments(self, parser):
        parser.add_argument('-d', '--domain', required=True)
        parser.add_argument('-i', '--id', required=True)
        parser.add_argument('-n', '--name', required=True)
        parser.add_argument('-v', '--version', required=True)
        parser.add_argument('-t', '--task-list')

        parser.add_argument(
            '--input',
            help='Raw input data for this execution',
            metavar='"<Some data>"')
        parser.add_argument(
            '--tag-list',
            help='List of tags to associate with the workflow execution',
            metavar='"tag1 tag2 ..."')
        parser.add_argument(
            '--execution-timeout',
            help='The maximum total duration for this workflow execution (seconds)')
        parser.add_argument(
            '--task-timeout',
            help='The maximum duration of decision tasks (seconds)')
        parser.add_argument(
            '--child-policy',
            help='Policy to use for the child executions of this execution')
        parser.add_argument(
            '--lambda-role',
            help='ARN of an IAM role that authorizes SWF to invoke Lambda functions')

    def run(self):
        connection = get_swf_connection()

        args = {}
        if self.args.input:
            args['input'] = self.args.input
        if self.args.task_list:
            args['task_list'] = self.args.task_list
        if self.args.tag_list:
            args['tagList'] = self.args.tag_list.split()
        if self.args.execution_timeout:
            args['executionStartToCloseTimeout'] = self.args.execution_timeout
        if self.args.task_timeout:
            args['taskStartToCloseTimeout'] = self.args.task_timeout
        if self.args.child_policy:
            args['childPolicy'] = self.args.child_policy
        if self.args.lambda_role:
            args['lambdaRole'] = self.args.lambda_role

        try:
            response = connection.start_workflow_execution(
                domain=self.args.domain,
                workflowId=self.args.id,
                workflowType={
                    'name': self.args.name,
                    'version': self.args.version
                    },
                **args)
        except ClientError as err:
            sys.exit(err)
        else:
            if is_response_success(response):
                print 'Workflow execution successfully created as RunId %s' % (
                    response['runId'])
            else:
                sys.exit('Error: %s' % response)
{'fraction_non_alphanumeric': 0.11025551277563878, 'fraction_numerical': 0.0007000350017500875, 'mean_word_length': 1.9550155118924508, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4479314', 'n_tokens_mistral': 1553, 'n_tokens_neox': 1498, 'n_words': 350}