Skip to content

Commit

Permalink
quote $@ to avoid splitting on whitespace in bash; related to #300
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorrit Poelen committed Oct 2, 2024
1 parent bc774b5 commit d226274
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion preston-cli/src/main/deb/bin/preston
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# Launches Preston in JVM
#

java -Xmx4G -XX:+UseG1GC -cp "/usr/share/preston/lib/*" bio.guoda.preston.Preston $@
java -Xmx4G -XX:+UseG1GC -cp "/usr/share/preston/lib/*" bio.guoda.preston.Preston "$@"
17 changes: 17 additions & 0 deletions preston-cli/src/test/java/bio/guoda/preston/PrestonTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bio.guoda.preston;

import bio.guoda.preston.cmd.CmdHistory;
import bio.guoda.preston.cmd.CmdTrack;
import org.junit.Test;
import picocli.CommandLine;

Expand All @@ -24,6 +25,22 @@ public void parseRemotesWithCommas() {
assertTwoRemotes(parseResult);
}

@Test
public void parseMessagePhrase() {
CommandLine commandLine = Preston.getCommandLine();
CommandLine.ParseResult parseResult = commandLine.parseArgs("track",
"--message",
"hello world");
assertThat(parseResult, is(notNullValue()));

CommandLine.ParseResult subcommand = parseResult.subcommand();
Object o = subcommand.commandSpec().userObject();
assertTrue(o instanceof CmdTrack);
CmdTrack cmd = (CmdTrack) o;

assertThat(cmd.getActivityDescription(), is("hello world"));
}

@Test
public void parseRemotes() {
CommandLine commandLine = Preston.getCommandLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public abstract class CmdActivity extends LoggingPersisting implements Runnable

@CommandLine.Option(
names = {"-m", "--message"},
split = " ",
arity = "1..*",
description = "Custom description of this tracking activity or command. (default: \"${DEFAULT-VALUE}\")"
)
private List<String> description = Arrays.asList(getDescriptionDefault());
private String description = getDescriptionDefault();

public abstract String getDescriptionDefault();

Expand Down Expand Up @@ -172,7 +172,7 @@ static List<Quad> findActivityInfo(ActivityContext activity) {
}

public String getActivityDescription() {
return StringUtils.join(description, " ");
return description;
}

private static class LoggerExitHook extends Thread {
Expand Down

0 comments on commit d226274

Please sign in to comment.