Skip to content
Merged
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
257 changes: 180 additions & 77 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
*/
public class InvalidArgTypeArgsException extends ArgsException {
public InvalidArgTypeArgsException(String flagName, String typeName, String message) {
super("Failed to set argument for " + flagName + " of type " + typeName + ": " + message, true);
super("Failed to set argument for " + flagName + " of type " + typeName + ":\n\t" + message, true);
}
}
11 changes: 11 additions & 0 deletions src/ArgsParser/ArgsExceptions/NotExistingPathArgsException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ArgsParser.ArgsExceptions;

import ArgsParser.ArgsException;

import java.nio.file.Path;

public class NotExistingPathArgsException extends ArgsException {
public NotExistingPathArgsException(Path path) {
super(path + " does not exist!\n\tInvalid path!", false);
}
}
716 changes: 154 additions & 562 deletions src/ArgsParser/ArgsParser.java

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/ArgsParser/CalledForHelpNotification.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ public class CalledForHelpNotification extends Exception {
private static final int consoleWidth = 100;
private static final Map<String, String> shortFlagTypes = new HashMap<>(){{
put("String", "s");
put("Path", "p");
put("Integer", "i");
put("Float", "f");
put("Double", "d");
put("Boolean", "b");
put("Character", "c");
put("String[]", "s+");
put("Path[]", "p+");
put("Integer[]", "i+");
put("Float[]", "f+");
put("Double[]", "d+");
put("Boolean[]", "b+");
put("Character[]", "c+");
Expand Down Expand Up @@ -90,12 +94,12 @@ private static String centerString(String stringToCenter) {
int freeSpace = (consoleWidth - stringToCenter.length()) / 2 - 1;
return "#" + " ".repeat(freeSpace) + stringToCenter;
}


//TODO abstract commandHelpString and ParameterHelpString
private static String commandHelpString(Command command, int longestFlagSize, int longestShortFlag) {
String fullCommandName = command.getFullCommandName();
String shortCommandName = command.getShortCommandName();
String description = command.getDescription();
String isMandatory = " ";
StringBuilder helpString = new StringBuilder("### ");

// check if a description is available:
Expand Down
12 changes: 8 additions & 4 deletions src/ArgsParser/Command.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package ArgsParser;

public class Command {
private final ArgsParser argsParser;
private final String fullCommandName;
private final String shortCommandName;
private final String description;
private ArgsParser argsParser;
private boolean status = false;

/**
Expand All @@ -13,12 +13,14 @@ public class Command {
* @param fullCommandName the detailed or long form flag for this command
* @param shortCommandName the abbreviated or short form flag for this command
* @param description a brief description of what this command does
* @param argsParser the parser responsible for handling command-line arguments
*/
public Command(String fullCommandName, String shortCommandName, String description, ArgsParser argsParser) {
public Command(String fullCommandName, String shortCommandName, String description) {
this.fullCommandName = fullCommandName;
this.shortCommandName = shortCommandName;
this.description = description;
}

protected void setArgsParser(ArgsParser argsParser) {
this.argsParser = argsParser;
}

Expand Down Expand Up @@ -61,8 +63,10 @@ protected void setCommand() {
*
* @return true if the command is provided, false otherwise.
* @throws IllegalArgumentException if the {@link ArgsParser#parse(String[] args)} method was not called before checking the command.
* or if this Command was not added to any {@link ArgsParser}!
*/
public boolean isProvided() throws IllegalArgumentException {
public boolean isProvided() throws IllegalStateException {
if (argsParser == null) throw new IllegalStateException("Command: " + this + " is not assigned to any parser instance!");
if (!argsParser.parseArgsWasCalled()) throw new IllegalStateException("parse() was not called before trying to check the command!");
return status;
}
Expand Down
Loading