Skip to content

Commit 1305dad

Browse files
hpmellemaSteven Yuan
authored and
Steven Yuan
committed
Add default template (smithy-lang#1843)
* Add default template
1 parent b6b331a commit 1305dad

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

smithy-cli/src/it/java/software/amazon/smithy/cli/InitCommandTest.java

+13-6
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,30 @@ public void init() {
3434
}
3535

3636
@Test
37-
public void missingTemplate() {
37+
public void usesDefaultTemplate() {
3838
IntegUtils.withProject(PROJECT_NAME, templatesDir -> {
3939
setupTemplatesDirectory(templatesDir);
4040

41-
IntegUtils.withTempDir("missingTemplate", dir -> {
41+
IntegUtils.withTempDir("defaultTemplate", dir -> {
4242
RunResult result = IntegUtils.run(
43-
dir, ListUtils.of("init", "-u", templatesDir.toString()));
43+
dir, ListUtils.of("init", "-u", templatesDir.toString()));
4444
assertThat(result.getOutput(),
45-
containsString("Please specify a template using `--template` or `-t`"));
46-
assertThat(result.getExitCode(), is(1));
45+
containsString("Smithy project created in directory: quickstart-cli"));
46+
assertThat(result.getExitCode(), is(0));
4747
});
48+
});
49+
}
50+
51+
@Test
52+
public void missingTemplate() {
53+
IntegUtils.withProject(PROJECT_NAME, templatesDir -> {
54+
setupTemplatesDirectory(templatesDir);
4855

4956
IntegUtils.withTempDir("emptyTemplateName", dir -> {
5057
RunResult result = IntegUtils.run(
5158
dir, ListUtils.of("init", "-t", "", "-u", templatesDir.toString()));
5259
assertThat(result.getOutput(),
53-
containsString("Please specify a template using `--template` or `-t`"));
60+
containsString("Please specify a template name using `--template` or `-t`"));
5461
assertThat(result.getExitCode(), is(1));
5562
});
5663
});

smithy-cli/src/main/java/software/amazon/smithy/cli/commands/InitCommand.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
final class InitCommand implements Command {
4545
private static final String SMITHY_TEMPLATE_JSON = "smithy-templates.json";
4646
private static final String DEFAULT_REPOSITORY_URL = "https://github.com/smithy-lang/smithy-examples.git";
47-
47+
private static final String DEFAULT_TEMPLATE_NAME = "quickstart-cli";
4848
private static final String DOCUMENTATION = "documentation";
4949

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

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

163163
ObjectNode templatesNode = getTemplatesNode(smithyTemplatesNode);
@@ -275,7 +275,7 @@ private static String pad(String s, int n) {
275275
}
276276

277277
private static final class Options implements ArgumentReceiver {
278-
private String template;
278+
private String template = DEFAULT_TEMPLATE_NAME;
279279
private String directory;
280280
private Boolean listTemplates = false;
281281
private String repositoryUrl = DEFAULT_REPOSITORY_URL;

0 commit comments

Comments
 (0)