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

Update init command to honor quiet setting #1889

Merged
merged 1 commit into from
Jul 28, 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 @@ -2,6 +2,7 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.emptyString;
import static org.hamcrest.Matchers.is;
import org.junit.jupiter.api.Test;
import software.amazon.smithy.utils.IoUtils;
Expand Down Expand Up @@ -232,6 +233,22 @@ public void outputDirectoryAlreadyExists() {
});
}

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

IntegUtils.withTempDir("exitZeroQuiet", dir -> {
RunResult result = IntegUtils.run(
dir, ListUtils.of("init", "--quiet", "-t", "quickstart-cli", "-u", templatesDir.toString()));

assertThat(result.getOutput().trim(), emptyString());
assertThat(result.getExitCode(), is(0));
assertThat(Files.exists(Paths.get(dir.toString(), "quickstart-cli")), is(true));
});
});
}

private static void run(List<String> args, Path root) {
StringBuilder output = new StringBuilder();
int result = IoUtils.runCommand(args, root, output, Collections.emptyMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import software.amazon.smithy.cli.ColorTheme;
import software.amazon.smithy.cli.Command;
import software.amazon.smithy.cli.HelpPrinter;
import software.amazon.smithy.cli.StandardOptions;
import software.amazon.smithy.model.node.Node;
import software.amazon.smithy.model.node.ObjectNode;
import software.amazon.smithy.model.node.StringNode;
Expand Down Expand Up @@ -83,6 +84,8 @@ public int execute(Arguments arguments, Env env) {

private int run(Arguments arguments, Env env) {
Options options = arguments.getReceiver(Options.class);
StandardOptions standardOptions = arguments.getReceiver(StandardOptions.class);

try {
final Path root = Paths.get(".");
final Path temp = Files.createTempDirectory("temp");
Expand All @@ -94,7 +97,7 @@ private int run(Arguments arguments, Env env) {
if (options.listTemplates) {
this.listTemplates(smithyTemplatesNode, env);
} else {
this.cloneTemplate(temp, smithyTemplatesNode, options.template, options.directory, env);
this.cloneTemplate(temp, smithyTemplatesNode, options, standardOptions, env);
}
} catch (IOException | InterruptedException | URISyntaxException e) {
throw new RuntimeException(e);
Expand Down Expand Up @@ -153,9 +156,13 @@ private String getTemplateList(ObjectNode smithyTemplatesNode, Env env) {
return builder.toString();
}

private void cloneTemplate(Path temp, ObjectNode smithyTemplatesNode, String template, String directory, Env env)
private void cloneTemplate(Path temp, ObjectNode smithyTemplatesNode, Options options,
StandardOptions standardOptions, Env env)
throws IOException, InterruptedException, URISyntaxException {

String template = options.template;
String directory = options.directory;

if (template == null || template.isEmpty()) {
throw new IllegalArgumentException("Please specify a template name using `--template` or `-t`");
}
Expand Down Expand Up @@ -194,8 +201,10 @@ private void cloneTemplate(Path temp, ObjectNode smithyTemplatesNode, String tem
IoUtils.copyDir(Paths.get(temp.toString(), templatePath), dest);
copyIncludedFiles(temp.toString(), dest.toString(), includedFiles, template, env);

try (ColorBuffer buffer = ColorBuffer.of(env.colors(), env.stderr())) {
buffer.println(String.format("Smithy project created in directory: %s", directory), ColorTheme.SUCCESS);
if (!standardOptions.quiet()) {
try (ColorBuffer buffer = ColorBuffer.of(env.colors(), env.stderr())) {
buffer.println(String.format("Smithy project created in directory: %s", directory), ColorTheme.SUCCESS);
}
}
}

Expand Down