From 7c85f5b9badf4a1921596091704bc8ed172ad738 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Thu, 31 Aug 2023 10:41:41 +0300 Subject: [PATCH] #534 --help works --- src/main/java/org/jpeek/Main.java | 22 +++++++++++++++++----- src/test/java/org/jpeek/MainTest.java | 2 -- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jpeek/Main.java b/src/main/java/org/jpeek/Main.java index a4562a4c..f3ca5ca7 100644 --- a/src/main/java/org/jpeek/Main.java +++ b/src/main/java/org/jpeek/Main.java @@ -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, @@ -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." diff --git a/src/test/java/org/jpeek/MainTest.java b/src/test/java/org/jpeek/MainTest.java index c17a1a6b..db7518b8 100644 --- a/src/test/java/org/jpeek/MainTest.java +++ b/src/test/java/org/jpeek/MainTest.java @@ -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; @@ -45,7 +44,6 @@ public final class MainTest { @Test - @Disabled public void printsHelp() throws IOException { Main.main("--help"); }