Merge branch '15-create-list-of-plugins' into 'master'
Resolve "Create list of plugins" Closes #15 See merge request bartlomiej.pluta/esa-tool!15
This commit is contained in:
@@ -1,14 +1,23 @@
|
|||||||
package com.bartek.esa.cli.di;
|
package com.bartek.esa.cli.di;
|
||||||
|
|
||||||
import com.bartek.esa.cli.parser.CliArgsParser;
|
import com.bartek.esa.cli.parser.CliArgsParser;
|
||||||
|
import com.bartek.esa.cli.printer.PluginPrinter;
|
||||||
|
import com.bartek.esa.core.archetype.Plugin;
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
public class CliModule {
|
public class CliModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
CliArgsParser cliArgsParser() {
|
public CliArgsParser cliArgsParser(PluginPrinter pluginPrinter) {
|
||||||
return new CliArgsParser();
|
return new CliArgsParser(pluginPrinter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
public PluginPrinter pluginPrinter(Set<Plugin> plugins) {
|
||||||
|
return new PluginPrinter(plugins);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.bartek.esa.cli.parser;
|
package com.bartek.esa.cli.parser;
|
||||||
|
|
||||||
import com.bartek.esa.cli.model.CliArgsOptions;
|
import com.bartek.esa.cli.model.CliArgsOptions;
|
||||||
|
import com.bartek.esa.cli.printer.PluginPrinter;
|
||||||
import com.bartek.esa.core.model.enumeration.Severity;
|
import com.bartek.esa.core.model.enumeration.Severity;
|
||||||
import org.apache.commons.cli.*;
|
import org.apache.commons.cli.*;
|
||||||
|
|
||||||
@@ -21,9 +22,14 @@ public class CliArgsParser {
|
|||||||
private static final String COLOR_OPT = "color";
|
private static final String COLOR_OPT = "color";
|
||||||
private static final String SEVERITIES_OPT = "severities";
|
private static final String SEVERITIES_OPT = "severities";
|
||||||
private static final String DEBUG_OPT = "debug";
|
private static final String DEBUG_OPT = "debug";
|
||||||
|
private static final String LIST_PLUGINS_OPT = "list-plugins";
|
||||||
|
|
||||||
|
private final PluginPrinter pluginPrinter;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public CliArgsParser() {}
|
public CliArgsParser(PluginPrinter pluginPrinter) {
|
||||||
|
this.pluginPrinter = pluginPrinter;
|
||||||
|
}
|
||||||
|
|
||||||
public CliArgsOptions parse(String[] args) {
|
public CliArgsOptions parse(String[] args) {
|
||||||
try {
|
try {
|
||||||
@@ -43,6 +49,12 @@ public class CliArgsParser {
|
|||||||
return CliArgsOptions.empty();
|
return CliArgsOptions.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (command.hasOption(LIST_PLUGINS_OPT)) {
|
||||||
|
pluginPrinter.printPlugins();
|
||||||
|
|
||||||
|
return CliArgsOptions.empty();
|
||||||
|
}
|
||||||
|
|
||||||
boolean isNeitherAuditNorAnalysis = !command.hasOption(SRC_OPT) && !command.hasOption(APK_OPT);
|
boolean isNeitherAuditNorAnalysis = !command.hasOption(SRC_OPT) && !command.hasOption(APK_OPT);
|
||||||
if (isNeitherAuditNorAnalysis) {
|
if (isNeitherAuditNorAnalysis) {
|
||||||
printHelp();
|
printHelp();
|
||||||
@@ -75,6 +87,7 @@ public class CliArgsParser {
|
|||||||
options.addOption(color());
|
options.addOption(color());
|
||||||
options.addOption(severities());
|
options.addOption(severities());
|
||||||
options.addOption(debug());
|
options.addOption(debug());
|
||||||
|
options.addOption(listPlugins());
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,4 +157,11 @@ public class CliArgsParser {
|
|||||||
.desc("enable debug mode")
|
.desc("enable debug mode")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Option listPlugins() {
|
||||||
|
return Option.builder()
|
||||||
|
.longOpt(LIST_PLUGINS_OPT)
|
||||||
|
.desc("list available plugins")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
26
src/main/java/com/bartek/esa/cli/printer/PluginPrinter.java
Normal file
26
src/main/java/com/bartek/esa/cli/printer/PluginPrinter.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package com.bartek.esa.cli.printer;
|
||||||
|
|
||||||
|
import com.bartek.esa.core.archetype.Plugin;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static java.lang.String.format;
|
||||||
|
|
||||||
|
public class PluginPrinter {
|
||||||
|
private final Set<Plugin> plugins;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public PluginPrinter(Set<Plugin> plugins) {
|
||||||
|
this.plugins = plugins;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void printPlugins() {
|
||||||
|
System.out.println("List of available plugins");
|
||||||
|
System.out.println(format("%-33s | Fully qualified plugin code", "Simple plugin code"));
|
||||||
|
plugins.stream()
|
||||||
|
.map(Object::getClass)
|
||||||
|
.map(p -> format(" - %-30s | - %s", p.getSimpleName(), p.getCanonicalName()))
|
||||||
|
.forEach(System.out::println);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user