Skip to content
Open
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
9 changes: 8 additions & 1 deletion src/main/java/bio/terra/cli/app/CommandRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -31,7 +32,13 @@ protected static String buildFullCommand(List<String> command) {
String fullCommand = "";
if (command != null && command.size() > 0) {
final String argSeparator = " ";
fullCommand += argSeparator + String.join(argSeparator, command);
fullCommand +=
argSeparator
+ String.join(
argSeparator,
command.stream()
.map(i -> "\"" + i.replace("\"", "\\\"") + "\"")
.collect(Collectors.toList()));
}
return fullCommand;
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/unit/PassthroughApps.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ void appList() throws IOException {
assertTrue(appList.containsAll(Arrays.asList("gcloud", "gsutil", "bq", "nextflow", "git")));
}

@Test
@DisplayName("app execute respects arguments with spaces")
void appExecuteSpace() throws IOException {
workspaceCreator.login(/*writeGcloudAuthFiles=*/ true);

// `terra workspace set --id=$id`
TestCommand.runAndParseCommandExpectSuccess(
UFWorkspace.class, "workspace", "set", "--id=" + getUserFacingId());

// `terra app execute sh -c "echo Hello World"`
TestCommand.Result cmd =
TestCommand.runCommand("app", "execute", "sh", "-c", "\"echo Hello World\"");

// Check that the output was printed
assertThat("Output is correct", cmd.stdOut, CoreMatchers.containsString("Hello World"));
}

@Test
@DisplayName("env vars include terra user and workspace cloud project")
void workspaceEnvVars() throws IOException {
Expand Down