diff --git a/src/main/java/com/askimed/nf/test/App.java b/src/main/java/com/askimed/nf/test/App.java index c33a00f5..6d385504 100644 --- a/src/main/java/com/askimed/nf/test/App.java +++ b/src/main/java/com/askimed/nf/test/App.java @@ -22,8 +22,6 @@ public class App { public int run(String[] args) { - printHeader(); - CommandLine commandLine = new CommandLine(new App()); commandLine.addSubcommand("clean", new CleanCommand()); commandLine.addSubcommand("init", new InitCommand()); @@ -38,16 +36,6 @@ public int run(String[] args) { } - private void printHeader() { - - System.out.println(); - System.out.println(Emoji.ROCKET + AnsiText.bold(" " + App.NAME + " " + App.VERSION)); - System.out.println("https://code.askimed.com/nf-test"); - System.out.println("(c) 2021 - 2023 Lukas Forer and Sebastian Schoenherr"); - System.out.println(); - - } - public static void main(String[] args) throws Exception { App app = new App(); diff --git a/src/main/java/com/askimed/nf/test/commands/AbstractCommand.java b/src/main/java/com/askimed/nf/test/commands/AbstractCommand.java new file mode 100644 index 00000000..abf29b05 --- /dev/null +++ b/src/main/java/com/askimed/nf/test/commands/AbstractCommand.java @@ -0,0 +1,40 @@ +package com.askimed.nf.test.commands; + +import java.util.concurrent.Callable; + +import com.askimed.nf.test.App; +import com.askimed.nf.test.util.AnsiText; +import com.askimed.nf.test.util.Emoji; + +import picocli.CommandLine.Option; +import picocli.CommandLine.Help.Visibility; + +public abstract class AbstractCommand implements Callable { + + @Option(names = { + "--silent" }, description = "Hide header and program version", required = false, showDefaultValue = Visibility.ALWAYS) + private boolean silent = false; + + @Override + public Integer call() throws Exception { + + if (!silent) { + printHeader(); + } + + return execute(); + } + + public abstract Integer execute() throws Exception; + + private void printHeader() { + + System.out.println(); + System.out.println(Emoji.ROCKET + AnsiText.bold(" " + App.NAME + " " + App.VERSION)); + System.out.println("https://code.askimed.com/nf-test"); + System.out.println("(c) 2021 - 2023 Lukas Forer and Sebastian Schoenherr"); + System.out.println(); + + } + +} diff --git a/src/main/java/com/askimed/nf/test/commands/CleanCommand.java b/src/main/java/com/askimed/nf/test/commands/CleanCommand.java index f180b83e..fc43cc5f 100644 --- a/src/main/java/com/askimed/nf/test/commands/CleanCommand.java +++ b/src/main/java/com/askimed/nf/test/commands/CleanCommand.java @@ -1,7 +1,6 @@ package com.askimed.nf.test.commands; import java.io.File; -import java.util.concurrent.Callable; import com.askimed.nf.test.config.Config; import com.askimed.nf.test.util.AnsiColors; @@ -10,12 +9,12 @@ import picocli.CommandLine.Command; @Command(name = "clean") -public class CleanCommand implements Callable { +public class CleanCommand extends AbstractCommand { public static String NF_DIRECTORY = ".nf-test"; @Override - public Integer call() throws Exception { + public Integer execute() throws Exception { File workDir = new File(NF_DIRECTORY); diff --git a/src/main/java/com/askimed/nf/test/commands/InitCommand.java b/src/main/java/com/askimed/nf/test/commands/InitCommand.java index 43925ade..021fe408 100644 --- a/src/main/java/com/askimed/nf/test/commands/InitCommand.java +++ b/src/main/java/com/askimed/nf/test/commands/InitCommand.java @@ -1,7 +1,6 @@ package com.askimed.nf.test.commands; import java.io.File; -import java.util.concurrent.Callable; import com.askimed.nf.test.App; import com.askimed.nf.test.commands.init.InitTemplates; @@ -11,10 +10,10 @@ import picocli.CommandLine.Command; @Command(name = "init") -public class InitCommand implements Callable { +public class InitCommand extends AbstractCommand { @Override - public Integer call() throws Exception { + public Integer execute() throws Exception { try { diff --git a/src/main/java/com/askimed/nf/test/commands/ListTestsCommand.java b/src/main/java/com/askimed/nf/test/commands/ListTestsCommand.java index a0d7841e..a4337912 100644 --- a/src/main/java/com/askimed/nf/test/commands/ListTestsCommand.java +++ b/src/main/java/com/askimed/nf/test/commands/ListTestsCommand.java @@ -3,19 +3,18 @@ import java.io.File; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.Callable; import com.askimed.nf.test.config.Config; import com.askimed.nf.test.core.TestExecutionEngine; import com.askimed.nf.test.util.AnsiColors; import picocli.CommandLine.Command; +import picocli.CommandLine.Help.Visibility; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; -import picocli.CommandLine.Help.Visibility; @Command(name = "list") -public class ListTestsCommand implements Callable { +public class ListTestsCommand extends AbstractCommand { @Parameters(description = "list all tests") private List testPaths = new ArrayList(); @@ -24,8 +23,12 @@ public class ListTestsCommand implements Callable { "--debug" }, description = "Show debugging infos", required = false, showDefaultValue = Visibility.ALWAYS) private boolean debug = false; + @Option(names = { + "--tags" }, description = "Show all available tags", required = false, showDefaultValue = Visibility.ALWAYS) + private boolean tags = false; + @Override - public Integer call() throws Exception { + public Integer execute() throws Exception { try { @@ -65,7 +68,11 @@ public Integer call() throws Exception { TestExecutionEngine engine = new TestExecutionEngine(); engine.setScripts(scripts); - return engine.listTests(); + if (tags) { + return engine.listTags(); + } else { + return engine.listTests(); + } } catch (Throwable e) { diff --git a/src/main/java/com/askimed/nf/test/commands/RunTestsCommand.java b/src/main/java/com/askimed/nf/test/commands/RunTestsCommand.java index 854364a1..2d456e63 100644 --- a/src/main/java/com/askimed/nf/test/commands/RunTestsCommand.java +++ b/src/main/java/com/askimed/nf/test/commands/RunTestsCommand.java @@ -8,7 +8,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Vector; -import java.util.concurrent.Callable; import java.util.function.Consumer; import com.askimed.nf.test.config.Config; @@ -28,7 +27,7 @@ import picocli.CommandLine.Parameters; @Command(name = "test") -public class RunTestsCommand implements Callable { +public class RunTestsCommand extends AbstractCommand { @Parameters(description = "test files") private List testPaths = new ArrayList(); @@ -69,7 +68,8 @@ public class RunTestsCommand implements Callable { private List tags = new Vector(); @Override - public Integer call() throws Exception { + public Integer execute() throws Exception { + List scripts = new ArrayList(); PluginManager manager = new PluginManager(false); diff --git a/src/main/java/com/askimed/nf/test/commands/UpdatePluginsCommand.java b/src/main/java/com/askimed/nf/test/commands/UpdatePluginsCommand.java index 759d76eb..a1c8b0d1 100644 --- a/src/main/java/com/askimed/nf/test/commands/UpdatePluginsCommand.java +++ b/src/main/java/com/askimed/nf/test/commands/UpdatePluginsCommand.java @@ -1,7 +1,6 @@ package com.askimed.nf.test.commands; import java.io.File; -import java.util.concurrent.Callable; import com.askimed.nf.test.config.Config; import com.askimed.nf.test.plugins.PluginManager; @@ -10,10 +9,10 @@ import picocli.CommandLine.Command; @Command(name = "update-plugins") -public class UpdatePluginsCommand implements Callable { +public class UpdatePluginsCommand extends AbstractCommand { @Override - public Integer call() throws Exception { + public Integer execute() throws Exception { File configFile = new File(Config.FILENAME); diff --git a/src/main/java/com/askimed/nf/test/commands/VersionCommand.java b/src/main/java/com/askimed/nf/test/commands/VersionCommand.java index a90f6972..b36d6a3a 100644 --- a/src/main/java/com/askimed/nf/test/commands/VersionCommand.java +++ b/src/main/java/com/askimed/nf/test/commands/VersionCommand.java @@ -1,17 +1,15 @@ package com.askimed.nf.test.commands; -import java.util.concurrent.Callable; - import com.askimed.nf.test.nextflow.NextflowCommand; import com.askimed.nf.test.util.AnsiColors; import picocli.CommandLine.Command; @Command(name = "version") -public class VersionCommand implements Callable { +public class VersionCommand extends AbstractCommand { @Override - public Integer call() throws Exception { + public Integer execute() throws Exception { try { diff --git a/src/main/java/com/askimed/nf/test/core/TestExecutionEngine.java b/src/main/java/com/askimed/nf/test/core/TestExecutionEngine.java index ca6b12c9..623164bf 100644 --- a/src/main/java/com/askimed/nf/test/core/TestExecutionEngine.java +++ b/src/main/java/com/askimed/nf/test/core/TestExecutionEngine.java @@ -2,7 +2,7 @@ import java.io.File; import java.util.List; -import java.util.Vector; +import java.util.*; import com.askimed.nf.test.lang.TestSuiteBuilder; import com.askimed.nf.test.plugins.PluginManager; @@ -258,4 +258,38 @@ public int listTests() throws Throwable { } + public int listTags() throws Throwable { + + if (configFile != null) { + if (!configFile.exists()) { + System.out.println( + AnsiColors.red("Error: Test config file '" + configFile.getAbsolutePath() + "'not found")); + System.out.println(); + return 1; + } + } + + List testSuits = parse(tagQuery); + + if (testSuits.size() == 0) { + System.out.println(AnsiColors.red("Error: no valid tests found.")); + System.out.println(); + return 1; + } + + Set tags = new HashSet(); + for (ITestSuite testSuite : testSuits) { + tags.addAll(testSuite.getTags()); + for (ITest test : testSuite.getTests()) { + tags.addAll(test.getTags()); + } + } + + for (String tag : tags) { + System.out.println(tag); + } + return 0; + + } + }