Skip to content

Commit

Permalink
Add option to list all available tags
Browse files Browse the repository at this point in the history
  • Loading branch information
lukfor committed Aug 23, 2023
1 parent e267865 commit dd531f8
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 34 deletions.
12 changes: 0 additions & 12 deletions src/main/java/com/askimed/nf/test/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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();
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/com/askimed/nf/test/commands/AbstractCommand.java
Original file line number Diff line number Diff line change
@@ -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<Integer> {

@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();

}

}
5 changes: 2 additions & 3 deletions src/main/java/com/askimed/nf/test/commands/CleanCommand.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,12 +9,12 @@
import picocli.CommandLine.Command;

@Command(name = "clean")
public class CleanCommand implements Callable<Integer> {
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);

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/askimed/nf/test/commands/InitCommand.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,10 +10,10 @@
import picocli.CommandLine.Command;

@Command(name = "init")
public class InitCommand implements Callable<Integer> {
public class InitCommand extends AbstractCommand {

@Override
public Integer call() throws Exception {
public Integer execute() throws Exception {

try {

Expand Down
17 changes: 12 additions & 5 deletions src/main/java/com/askimed/nf/test/commands/ListTestsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> {
public class ListTestsCommand extends AbstractCommand {

@Parameters(description = "list all tests")
private List<File> testPaths = new ArrayList<File>();
Expand All @@ -24,8 +23,12 @@ public class ListTestsCommand implements Callable<Integer> {
"--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 {

Expand Down Expand Up @@ -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) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,7 +27,7 @@
import picocli.CommandLine.Parameters;

@Command(name = "test")
public class RunTestsCommand implements Callable<Integer> {
public class RunTestsCommand extends AbstractCommand {

@Parameters(description = "test files")
private List<File> testPaths = new ArrayList<File>();
Expand Down Expand Up @@ -69,7 +68,8 @@ public class RunTestsCommand implements Callable<Integer> {
private List<String> tags = new Vector<String>();

@Override
public Integer call() throws Exception {
public Integer execute() throws Exception {

List<File> scripts = new ArrayList<File>();
PluginManager manager = new PluginManager(false);

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,10 +9,10 @@
import picocli.CommandLine.Command;

@Command(name = "update-plugins")
public class UpdatePluginsCommand implements Callable<Integer> {
public class UpdatePluginsCommand extends AbstractCommand {

@Override
public Integer call() throws Exception {
public Integer execute() throws Exception {

File configFile = new File(Config.FILENAME);

Expand Down
Original file line number Diff line number Diff line change
@@ -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<Integer> {
public class VersionCommand extends AbstractCommand {

@Override
public Integer call() throws Exception {
public Integer execute() throws Exception {

try {

Expand Down
36 changes: 35 additions & 1 deletion src/main/java/com/askimed/nf/test/core/TestExecutionEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ITestSuite> testSuits = parse(tagQuery);

if (testSuits.size() == 0) {
System.out.println(AnsiColors.red("Error: no valid tests found."));
System.out.println();
return 1;
}

Set<String> tags = new HashSet<String>();
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;

}

}

0 comments on commit dd531f8

Please sign in to comment.