Skip to content

Commit

Permalink
CLI input checks
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo-patane committed Apr 10, 2020
1 parent fa70e1e commit ea5c65a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/main/java/qubo/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ private static void standardRun(String[] a)
}
Info.debugMode = i.isDebugMode();
quboInstance = new QuboInstance(i);
quboInstance.run();
try{
quboInstance.run();
}catch (NumberFormatException e){
quboInstance.inputData.help();
}
}

private static void txtRun()
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/qubo/InputData.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class InputData{
private boolean ping;
private final String filename;

private Options options;

private Options buildOptions()
{
Option iprange = new Option("range","iprange",true,"The IP range that qubo will scan");
Expand Down Expand Up @@ -79,14 +81,14 @@ private Options buildOptions()
return options;
}

private void help(Options options){
public void help(){
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("-range <arg> -ports <arg> -th <arg> -ti <arg>",options);
System.exit(-1);
}

public InputData(String[] command) throws InvalidRangeException,NumberFormatException {
Options options = buildOptions();
options = buildOptions();
CommandLineParser parser = new DefaultParser();
String ipStart = "",ipEnd = "";
try
Expand Down Expand Up @@ -114,7 +116,8 @@ public InputData(String[] command) throws InvalidRangeException,NumberFormatExce
}
catch (NullPointerException | IndexOutOfBoundsException e)
{
throw new InvalidRangeException();
if(Info.gui) throw new InvalidRangeException();
else help();
}

try
Expand All @@ -124,12 +127,17 @@ public InputData(String[] command) throws InvalidRangeException,NumberFormatExce
catch (IllegalArgumentException e){
throw new IllegalArgumentException(e.getMessage());
}
try{
portrange = new PortList(cmd.getOptionValue("ports"));
}catch (NumberFormatException e){
if(Info.gui) throw new NumberFormatException();
help();
}

portrange = new PortList(cmd.getOptionValue("ports"));
ping = !cmd.hasOption("noping");
} catch (ParseException e)
{
help(options); //help contiene system.exit
help(); //help contiene system.exit
}

if(isOutput())
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/qubo/gui/InstanceRunnable.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void run() {
quboInstance.run();
}
catch (NumberFormatException e){
if(Confirm.requestConfirm("Check input and relaunch program, would you like to see an example configuration?"))
if(Confirm.requestConfirm("Check threads or timeout fields and relaunch program, would you like to see an example configuration?"))
window.exampleConf();
}
window.idle();
Expand Down

0 comments on commit ea5c65a

Please sign in to comment.