Skip to content

Commit

Permalink
Add default template (smithy-lang#1843)
Browse files Browse the repository at this point in the history
* Add default template
  • Loading branch information
hpmellema authored and Steven Yuan committed Aug 11, 2023
1 parent b6b331a commit 1305dad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
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

0 comments on commit 1305dad

Please sign in to comment.