Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default template #1843

Merged
merged 2 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,30 @@ public void init() {
}

@Test
public void missingTemplate() {
public void usesDefaultTemplate() {
IntegUtils.withProject(PROJECT_NAME, templatesDir -> {
setupTemplatesDirectory(templatesDir);

IntegUtils.withTempDir("missingTemplate", dir -> {
IntegUtils.withTempDir("defaultTemplate", dir -> {
RunResult result = IntegUtils.run(
dir, ListUtils.of("init", "-u", templatesDir.toString()));
dir, ListUtils.of("init", "-u", templatesDir.toString()));
assertThat(result.getOutput(),
containsString("Please specify a template using `--template` or `-t`"));
assertThat(result.getExitCode(), is(1));
containsString("Smithy project created in directory: quickstart-cli"));
assertThat(result.getExitCode(), is(0));
});
});
}

@Test
public void missingTemplate() {
IntegUtils.withProject(PROJECT_NAME, templatesDir -> {
setupTemplatesDirectory(templatesDir);

IntegUtils.withTempDir("emptyTemplateName", dir -> {
RunResult result = IntegUtils.run(
dir, ListUtils.of("init", "-t", "", "-u", templatesDir.toString()));
assertThat(result.getOutput(),
containsString("Please specify a template using `--template` or `-t`"));
containsString("Please specify a template name using `--template` or `-t`"));
assertThat(result.getExitCode(), is(1));
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
final class InitCommand implements Command {
private static final String SMITHY_TEMPLATE_JSON = "smithy-templates.json";
private static final String DEFAULT_REPOSITORY_URL = "https://github.com/smithy-lang/smithy-examples.git";

private static final String DEFAULT_TEMPLATE_NAME = "quickstart-cli";
private static final String DOCUMENTATION = "documentation";

private static final String NAME = "name";
Expand Down Expand Up @@ -157,7 +157,7 @@ private void cloneTemplate(Path temp, ObjectNode smithyTemplatesNode, String tem
throws IOException, InterruptedException, URISyntaxException {

if (template == null || template.isEmpty()) {
throw new IllegalArgumentException("Please specify a template using `--template` or `-t`");
throw new IllegalArgumentException("Please specify a template name using `--template` or `-t`");
}

ObjectNode templatesNode = getTemplatesNode(smithyTemplatesNode);
Expand Down Expand Up @@ -275,7 +275,7 @@ private static String pad(String s, int n) {
}

private static final class Options implements ArgumentReceiver {
private String template;
private String template = DEFAULT_TEMPLATE_NAME;
private String directory;
private Boolean listTemplates = false;
private String repositoryUrl = DEFAULT_REPOSITORY_URL;
Expand Down