def _generate_from_app_template(location, runtime, dependency_manager,
                                output_dir, name, app_template):
    extra_context = None
    if not name:
        name = click.prompt("Project Name", type=str)
    if not runtime:
        runtime = click.prompt("Runtime", type=click.Choice(RUNTIMES))
    if not dependency_manager:
        valid_dep_managers = RUNTIME_TO_DEPENDENCY_MANAGERS.get(runtime)
        if valid_dep_managers is None:
            dependency_manager = None
        else:
            dependency_manager = click.prompt(
                "Dependency Manager",
                type=click.Choice(valid_dep_managers),
                default=valid_dep_managers[0])
    templates = InitTemplates()
    if app_template is not None:
        location = templates.location_from_app_template(
            runtime, dependency_manager, app_template)
        extra_context = {"project_name": name, "runtime": runtime}
    else:
        location = templates.prompt_for_location(runtime, dependency_manager)
        extra_context = {"project_name": name, "runtime": runtime}
    no_input = True
    if not output_dir:
        output_dir = click.prompt("Output Directory",
                                  type=click.Path(),
                                  default=".")
    do_generate(location, runtime, dependency_manager, output_dir, name,
                no_input, extra_context)
Пример #2
0
def _generate_from_app_template(location, runtime, dependency_manager,
                                output_dir, name, app_template):
    extra_context = None
    runtime = _get_runtime(runtime)
    dependency_manager = _get_dependency_manager(dependency_manager, runtime)
    if not name:
        name = click.prompt("\nProject name", type=str, default="sam-app")
    templates = InitTemplates()
    if app_template is not None:
        location = templates.location_from_app_template(
            runtime, dependency_manager, app_template)
        extra_context = {"project_name": name, "runtime": runtime}
    else:
        location, app_template = templates.prompt_for_location(
            runtime, dependency_manager)
        extra_context = {"project_name": name, "runtime": runtime}

    # executing event_bridge logic if call is for Schema dynamic template
    is_dynamic_schemas_template = templates.is_dynamic_schemas_template(
        app_template, runtime, dependency_manager)
    if is_dynamic_schemas_template:
        schemas_api_caller = get_schemas_api_caller()
        schema_template_details = _get_schema_template_details(
            schemas_api_caller)
        schemas_template_parameter = get_schemas_template_parameter(
            schema_template_details)
        extra_context = {**schemas_template_parameter, **extra_context}

    no_input = True
    summary_msg = """
-----------------------
Generating application:
-----------------------
Name: {name}
Runtime: {runtime}
Dependency Manager: {dependency_manager}
Application Template: {app_template}
Output Directory: {output_dir}

Next steps can be found in the README file at {output_dir}/{name}/README.md
    """.format(
        name=name,
        runtime=runtime,
        dependency_manager=dependency_manager,
        app_template=app_template,
        output_dir=output_dir,
    )
    click.echo(summary_msg)
    do_generate(location, runtime, dependency_manager, output_dir, name,
                no_input, extra_context)
    # executing event_bridge logic if call is for Schema dynamic template
    if is_dynamic_schemas_template:
        _package_schemas_code(runtime, schemas_api_caller,
                              schema_template_details, output_dir, name,
                              location)
Пример #3
0
 def test_fallback_options(self, git_exec_mock, prompt_mock, sd_mock):
     prompt_mock.return_value = "1"
     with patch("subprocess.check_output",
                new_callable=MagicMock) as mock_sub:
         with patch("samcli.cli.global_config.GlobalConfig.config_dir",
                    new_callable=PropertyMock) as mock_cfg:
             mock_sub.side_effect = OSError("Fail")
             mock_cfg.return_value = "/tmp/test-sam"
             it = InitTemplates(True)
             location = it.prompt_for_location("ruby2.5", "bundler")
             self.assertTrue(
                 search("cookiecutter-aws-sam-hello-ruby", location))
Пример #4
0
 def test_fallback_process_error(self, git_exec_mock, prompt_mock, sd_mock):
     prompt_mock.return_value = "1"
     with patch("subprocess.check_output",
                new_callable=MagicMock) as mock_sub:
         with patch("samcli.cli.global_config.GlobalConfig.config_dir",
                    new_callable=PropertyMock) as mock_cfg:
             mock_sub.side_effect = subprocess.CalledProcessError(
                 "fail", "fail", "not found".encode("utf-8"))
             mock_cfg.return_value = "/tmp/test-sam"
             it = InitTemplates(True)
             location, app_template = it.prompt_for_location(
                 "ruby2.5", "bundler")
             self.assertTrue(
                 search("cookiecutter-aws-sam-hello-ruby", location))
             self.assertEqual("hello-world", app_template)
Пример #5
0
def _generate_from_app_template(location, runtime, dependency_manager,
                                output_dir, name, app_template):
    extra_context = None
    if not runtime:
        choices = list(map(str, range(1, len(INIT_RUNTIMES) + 1)))
        choice_num = 1
        click.echo("\nWhich runtime would you like to use?")
        for r in INIT_RUNTIMES:
            msg = "\t" + str(choice_num) + " - " + r
            click.echo(msg)
            choice_num = choice_num + 1
        choice = click.prompt("Runtime",
                              type=click.Choice(choices),
                              show_choices=False)
        runtime = INIT_RUNTIMES[int(choice) - 1]  # zero index
    if not dependency_manager:
        valid_dep_managers = RUNTIME_TO_DEPENDENCY_MANAGERS.get(runtime)
        if valid_dep_managers is None:
            dependency_manager = None
        elif len(valid_dep_managers) == 1:
            dependency_manager = valid_dep_managers[0]
        else:
            choices = list(map(str, range(1, len(valid_dep_managers) + 1)))
            choice_num = 1
            click.echo("\nWhich dependency manager would you like to use?")
            for dm in valid_dep_managers:
                msg = "\t" + str(choice_num) + " - " + dm
                click.echo(msg)
                choice_num = choice_num + 1
            choice = click.prompt("Dependency manager",
                                  type=click.Choice(choices),
                                  show_choices=False)
            dependency_manager = valid_dep_managers[int(choice) -
                                                    1]  # zero index
    if not name:
        name = click.prompt("\nProject name", type=str, default="sam-app")
    templates = InitTemplates()
    if app_template is not None:
        location = templates.location_from_app_template(
            runtime, dependency_manager, app_template)
        extra_context = {"project_name": name, "runtime": runtime}
    else:
        location, app_template = templates.prompt_for_location(
            runtime, dependency_manager)
        extra_context = {"project_name": name, "runtime": runtime}
    no_input = True
    summary_msg = """
-----------------------
Generating application:
-----------------------
Name: {name}
Runtime: {runtime}
Dependency Manager: {dependency_manager}
Application Template: {app_template}
Output Directory: {output_dir}

Next steps can be found in the README file at {output_dir}/{name}/README.md
    """.format(
        name=name,
        runtime=runtime,
        dependency_manager=dependency_manager,
        app_template=app_template,
        output_dir=output_dir,
    )
    click.echo(summary_msg)
    do_generate(location, runtime, dependency_manager, output_dir, name,
                no_input, extra_context)