Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend list command by additional output formats #105

Merged
merged 4 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions docs/docs/cli/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ nf-test list [<NEXTFLOW_FILES>|<SCRIPT_FOLDERS>]

### Optional Arguments

#### `--tags`
Print a list of all used tags.

#### `--format json`
Print the list of tests or tags as json object.

#### `--format raw`
Print the list of tests or tags as simple list without formatting.

#### `--silent`
Hide program version and header infos.

#### `--debug`
Show debugging infos.

Expand All @@ -28,3 +40,36 @@ Show debugging infos.

nf-test list tests/modules tests/modules/bwa_index.nf.test
```

* List of all testcases as json:

```
nf-test list --format json --silent
["/Users/lukfor/Development/git/nf-gwas/tests/main.nf.test@69b98c67","/Users/lukfor/Development/git/nf-gwas/tests/main.nf.test@fdb6c1cc","/Users/lukfor/Development/git/nf-gwas/tests/main.nf.test@d1c219eb","/Users/lukfor/Development/git/nf-gwas/tests/main.nf.test@3c54e3cb",...]
```

* List of all testcases as unformatted ist:

```
nf-test list --format raw --silent
/Users/lukfor/Development/git/nf-gwas/tests/main.nf.test@69b98c67
/Users/lukfor/Development/git/nf-gwas/tests/main.nf.test@fdb6c1cc
/Users/lukfor/Development/git/nf-gwas/tests/main.nf.test@d1c219eb
/Users/lukfor/Development/git/nf-gwas/tests/main.nf.test@3c54e3cb
...
```

* List of all tags as json:

```
nf-test list --tags --format json --silent
["fastqc","snakemake"]
```

* List of all tags as unformatted list:

```
nf-test list --tags --format raw --silent
fastqc
snakemake
```
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
22 changes: 17 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,19 @@
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 com.askimed.nf.test.util.OutputFormat;

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 +24,16 @@ 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;

@Option(names = {
"--format" }, description = "Output format", required = false, showDefaultValue = Visibility.ALWAYS)
private OutputFormat format = OutputFormat.PRETTY;

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

try {

Expand Down Expand Up @@ -65,7 +73,11 @@ public Integer call() throws Exception {

TestExecutionEngine engine = new TestExecutionEngine();
engine.setScripts(scripts);
return engine.listTests();
if (tags) {
return engine.listTags(format);
} else {
return engine.listTests(format);
}

} 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
Loading
Loading