Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuckame committed Nov 2, 2020
1 parent cc0ac27 commit 78db0e9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {

application {
mainClass = 'fr.chuckame.marlinfw.configurator.MarlinConfigurator'
applicationDefaultJvmArgs = ['-Dapp-console-name=marlin-console-configurator.jar']
applicationDefaultJvmArgs = ['-Dapp-console-name=marlin-console-configurator']
}

test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,5 @@
public class MarlinConfigurator {
public static void main(final String[] args) {
SpringApplication.run(MarlinConfigurator.class, args);
// SpringApplication.run(MarlinConfigurator.class, "help");
// SpringApplication.run(MarlinConfigurator.class, "apply", "--save", "--profile", "src/test/resources/profile.yaml", "--file", "src/test/resources/file.h");
//SpringApplication.run(MarlinConfigurator.class, "generate-profile", "src/test/resources/file.h", "--output", "src/test/resources/profile.yaml");
// SpringApplication.run(MarlinConfigurator.class, "generate-profile", "src/test/resources/file.h", "--output", "console");
// SpringApplication.run(MarlinConfigurator.class, "diff", "--left", "src/test/resources/file.h", "--right", "src/test/resources/file2.h");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,37 @@ public class CommandRunner implements CommandLineRunner {
private final ConsoleHelper consoleHelper;

@Override
public void run(final String... args) throws Exception {
public void run(final String[] args) throws Exception {
try {
jCommander.parse(args);
} catch (final ParameterException e) {
consoleHelper.writeErrorLine("Bad argument: " + e.getMessage());
consoleHelper.writeLine(jCommander.getUsageFormatter()::usage);
System.exit(InvalidUseException.EXIT_CODE);
}
try {
final Command command = (Command) jCommander.findCommandByAlias(jCommander.getParsedAlias()).getObjects().get(0);
command.run().blockOptional();
findCommandByAlias(parseAlias(args)).run().blockOptional();
} catch (final ManuallyStoppedException e) {
consoleHelper.writeErrorLine(e.getMessage());
System.exit(e.getExitCode());
}
}

private String parseAlias(final String[] args) {
String errorMessage = null;
try {
jCommander.parse(args);
} catch (final ParameterException e) {
errorMessage = e.getMessage();
}
if (errorMessage == null && jCommander.getParsedAlias() != null) {
return jCommander.getParsedAlias();
}

if (errorMessage == null) {
consoleHelper.writeErrorLine("No argument passed");
} else {
consoleHelper.writeErrorLine("Bad argument: " + errorMessage);
}
consoleHelper.writeLine(jCommander.getUsageFormatter()::usage);
System.exit(InvalidUseException.EXIT_CODE);
return null;
}

private Command findCommandByAlias(final String alias) {
return (Command) jCommander.findCommandByAlias(alias).getObjects().get(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void writeLine(final String line) {
public void writeLine(final Consumer<StringBuilder> lineBuilder) {
final var line = new StringBuilder();
lineBuilder.accept(line);
writeLine(lineBuilder.toString());
writeLine(line.toString());
}

public void writeErrorLine(final String line) {
Expand Down

0 comments on commit 78db0e9

Please sign in to comment.