Skip to content

Commit c6d8ae7

Browse files
author
Muhammad Hashim
committed
two new methods to add arguments and options.
1 parent beaade5 commit c6d8ae7

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/mhashim6/commander/main/CommandBuilder.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public CommandBuilder forCommandLine(String line) {
4444
}
4545
// ============================================================
4646

47+
public CommandBuilder addOption(String option) {
48+
if (option != null) cmdOptions.add(option);
49+
50+
return this;
51+
}
52+
4753
/**
4854
* side effect: will clear any previously set options if any.
4955
*/
@@ -54,6 +60,12 @@ public CommandBuilder withOptions(String... params) {
5460
}
5561
// ============================================================
5662

63+
public CommandBuilder addArg(String arg) {
64+
if (arg != null) cmdArgs.add(arg);
65+
66+
return this;
67+
}
68+
5769
/**
5870
* side effect: will clear any previously set arguments if any.
5971
*/
@@ -84,7 +96,7 @@ private ArrayList<String> finalCmdList() {
8496
// ============================================================
8597

8698
private static String[] splitCmd(String cmd) {
87-
List<String> strings = new ArrayList<String>();
99+
List<String> strings = new ArrayList<>();
88100
Matcher m = QUOTES_PATTERN.matcher(cmd);
89101
while (m.find())
90102
strings.add(m.group(1));
@@ -123,5 +135,9 @@ public String string() {
123135
return cmdLine;
124136
}
125137

138+
@Override
139+
public String toString() {
140+
return string();
141+
}
126142
}
127143
}

0 commit comments

Comments
 (0)