Skip to content

Commit 1818ffb

Browse files
committed
add GitCommand example
1 parent 0b04c9f commit 1818ffb

4 files changed

Lines changed: 54 additions & 119 deletions

File tree

examples/src/main/java/net/jbock/examples/GitArguments.java

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package net.jbock.examples;
2+
3+
import net.jbock.Command;
4+
import net.jbock.Parameter;
5+
import net.jbock.SuperCommand;
6+
import net.jbock.VarargsParameter;
7+
8+
import java.util.List;
9+
10+
@SuperCommand(
11+
name = "git",
12+
description = "Git is software for tracking changes in any set of files.")
13+
interface GitCommand {
14+
15+
@Command(
16+
name = "git-add",
17+
description = "Add file contents to the index")
18+
interface AddCommand {
19+
@VarargsParameter
20+
List<String> pathspec();
21+
22+
// more parameters and options...
23+
}
24+
25+
@Parameter(index = 0)
26+
String command();
27+
28+
// more options...
29+
}

examples/src/test/java/net/jbock/examples/GitArgumentsTest.java

Lines changed: 0 additions & 84 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package net.jbock.examples;
2+
3+
import net.jbock.examples.GitCommand.AddCommand;
4+
import net.jbock.util.SuperResult;
5+
import org.junit.jupiter.api.Test;
6+
7+
import java.util.List;
8+
9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
11+
class GitCommandTest {
12+
13+
private final GitCommandParser gitParser = new GitCommandParser();
14+
private final GitCommand_AddCommandParser addParser = new GitCommand_AddCommandParser();
15+
16+
@Test
17+
void testEscape() {
18+
String[] args = {"add", "foo", "bar"};
19+
SuperResult<GitCommand> result = gitParser.parse(List.of(args)).getRight().orElseThrow();
20+
GitCommand gitCommand = result.getCommand();
21+
assertEquals("add", gitCommand.command());
22+
AddCommand addCommand = addParser.parse(List.of(result.getRest())).getRight().orElseThrow();
23+
assertEquals(List.of("foo", "bar"), addCommand.pathspec());
24+
}
25+
}

0 commit comments

Comments
 (0)