コード例 #1
0
ファイル: __init__.py プロジェクト: sysad-aldama/aws-sam-cli
def do_cli(
    ctx,
    no_interactive,
    location,
    runtime,
    dependency_manager,
    output_dir,
    name,
    app_template,
    no_input,
    extra_context,
    auto_clone=True,
):
    from samcli.commands.init.init_generator import do_generate
    from samcli.commands.init.init_templates import InitTemplates
    from samcli.commands.init.interactive_init_flow import do_interactive

    # check for mutually exclusive parameters
    if location and app_template:
        msg = """
You must not provide both the --location and --app-template parameters.

You can run 'sam init' without any options for an interactive initialization flow, or you can provide one of the following required parameter combinations:
    --name and --runtime and --app-template and --dependency-manager
    --location
        """
        raise UserException(msg)
    # check for required parameters
    if location or (name and runtime and dependency_manager and app_template):
        # need to turn app_template into a location before we generate
        if app_template:
            templates = InitTemplates(no_interactive, auto_clone)
            location = templates.location_from_app_template(
                runtime, dependency_manager, app_template)
            no_input = True
            default_context = {"project_name": name, "runtime": runtime}
            if extra_context is None:
                extra_context = default_context
            else:
                extra_context = _merge_extra_context(default_context,
                                                     extra_context)
        if not output_dir:
            output_dir = "."
        do_generate(location, runtime, dependency_manager, output_dir, name,
                    no_input, extra_context)
    elif no_interactive:
        error_msg = """
ERROR: Missing required parameters, with --no-interactive set.

Must provide one of the following required parameter combinations:
    --name and --runtime and --dependency-manager and --app-template
    --location

You can also re-run without the --no-interactive flag to be prompted for required values.
        """
        raise UserException(error_msg)
    else:
        # proceed to interactive state machine, which will call do_generate
        do_interactive(location, runtime, dependency_manager, output_dir, name,
                       app_template, no_input)
コード例 #2
0
ファイル: __init__.py プロジェクト: wchengru/aws-sam-cli
def do_cli(
    ctx,
    no_interactive,
    location,
    pt_explicit,
    package_type,
    runtime,
    base_image,
    dependency_manager,
    output_dir,
    name,
    app_template,
    no_input,
    extra_context,
    auto_clone=True,
):
    """
    Implementation of the ``cli`` method
    """

    from samcli.commands.init.init_generator import do_generate
    from samcli.commands.init.interactive_init_flow import do_interactive
    from samcli.commands.init.init_templates import InitTemplates
    from samcli.commands.exceptions import LambdaImagesTemplateException

    _deprecate_notification(runtime)

    # check for required parameters
    zip_bool = name and runtime and dependency_manager and app_template
    image_bool = name and pt_explicit and base_image
    if location or zip_bool or image_bool:
        # need to turn app_template into a location before we generate
        templates = InitTemplates(no_interactive, auto_clone)
        if package_type == IMAGE and image_bool:
            base_image, runtime = _get_runtime_from_image(base_image)
            options = templates.init_options(package_type, runtime, base_image,
                                             dependency_manager)
            if len(options) == 1:
                app_template = options[0].get("appTemplate")
            elif len(options) > 1:
                raise LambdaImagesTemplateException(
                    "Multiple lambda image application templates found. "
                    "This should not be possible, please raise an issue.")

        if app_template and not location:
            location = templates.location_from_app_template(
                package_type, runtime, base_image, dependency_manager,
                app_template)
            no_input = True
        extra_context = _get_cookiecutter_template_context(
            name, runtime, extra_context)

        if not output_dir:
            output_dir = "."
        do_generate(location, package_type, runtime, dependency_manager,
                    output_dir, name, no_input, extra_context)
    else:
        # proceed to interactive state machine, which will call do_generate
        do_interactive(
            location,
            pt_explicit,
            package_type,
            runtime,
            base_image,
            dependency_manager,
            output_dir,
            name,
            app_template,
            no_input,
        )