Skip to content

Commit

Permalink
#534 --help works
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Aug 31, 2023
1 parent 39f29c5 commit 7c85f5b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 17 additions & 5 deletions src/main/java/org/jpeek/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@
*/
public final class Main {

@Parameter(
names = "--help",
help = true,
description = "Print usage options"
)
private boolean help;

@Parameter(
names = { "--sources", "-s" },
converter = FileConverter.class,
Expand Down Expand Up @@ -111,18 +118,23 @@ private Main() {
*/
public static void main(final String... args) throws IOException {
final Main main = new Main();
JCommander.newBuilder()
final JCommander jcmd = JCommander.newBuilder()
.addObject(main)
.build()
.parse(args);
main.run();
.build();
jcmd.parse(args);
main.run(jcmd);
}

/**
* Run it.
* @param jcmd The command line opts
* @throws IOException If fails
*/
private void run() throws IOException {
private void run(final JCommander jcmd) throws IOException {
if (this.help) {
jcmd.usage();
return;
}
if (this.overwrite && this.sources.equals(this.target)) {
throw new IllegalArgumentException(
"Invalid paths - can't be equal if overwrite option is set."
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/org/jpeek/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import org.cactoos.Scalar;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.llorllale.cactoos.matchers.Assertion;
Expand All @@ -45,7 +44,6 @@
public final class MainTest {

@Test
@Disabled
public void printsHelp() throws IOException {
Main.main("--help");
}
Expand Down

0 comments on commit 7c85f5b

Please sign in to comment.