Skip to content

Commit 8331799

Browse files
committed
Parsing Combined Flags
- Proper argument parsing into separate flags for command execution - Example: Input '-la' is now correctly treated as '-l -a'.
1 parent 0e9d04a commit 8331799

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/com/unixtools/Main.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.unixtools;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
5+
36
import com.unixtools.core.CommandExecutor;
47

58
public class Main {
@@ -10,8 +13,19 @@ public static void main(String[] args) {
1013
}
1114

1215
String commandName = args[0];
13-
String[] commandArgs = new String[args.length - 1];
14-
System.arraycopy(args, 1, commandArgs, 0, args.length - 1);
16+
List<String> commandArgsList = new ArrayList<>();
17+
18+
for (int i = 1; i < args.length; i++) {
19+
if (args[i].startsWith("-") && args[i].length() > 1) {
20+
for (int j = 1; j < args[i].length(); j++) {
21+
commandArgsList.add("-" + args[i].charAt(j));
22+
}
23+
} else {
24+
commandArgsList.add(args[i]);
25+
}
26+
}
27+
28+
String[] commandArgs = commandArgsList.toArray(new String[0]);
1529

1630
CommandExecutor executor = new CommandExecutor();
1731
executor.executeCommand(commandName, commandArgs);

0 commit comments

Comments
 (0)