register bundled apps as services

This commit is contained in:
Jonathan Shook 2022-07-26 01:15:16 -05:00
parent 21ca1d1b2f
commit cec49d9d1c
4 changed files with 70 additions and 30 deletions

View File

@ -16,6 +16,8 @@
package io.nosqlbench.api.docsapi.docexporter;
import io.nosqlbench.api.spi.BundledApp;
import io.nosqlbench.nb.annotations.Service;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
@ -24,14 +26,19 @@ import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
public class BundledMarkdownExporter {
@Service(value=BundledApp.class,selector = "export-docs")
public class BundledMarkdownExporter implements BundledApp {
public static void main(String[] args) {
new BundledMarkdownExporter().appMain(args);
}
@Override
public int appMain(String[] args) {
final OptionParser parser = new OptionParser();
OptionSpec<String> zipfileSpec = parser.accepts("zipfile", "zip file to write to")
.withOptionalArg().ofType(String.class).defaultsTo("exported_docs.zip");
.withOptionalArg().ofType(String.class).defaultsTo("exported_docs.zip");
OptionSpec<?> helpSpec = parser.acceptsAll(List.of("help", "h", "?"), "Display help").forHelp();
OptionSet options = parser.parse(args);
@ -46,6 +53,6 @@ public class BundledMarkdownExporter {
String zipfile = options.valueOf(zipfileSpec);
new BundledMarkdownZipExporter(new BundledFrontmatterInjector()).exportDocs(Path.of(zipfile));
return 0;
}
}

View File

@ -19,6 +19,8 @@ package io.nosqlbench.api.markdown.exporter;
import io.nosqlbench.api.markdown.aggregator.MarkdownDocs;
import io.nosqlbench.api.markdown.types.DocScope;
import io.nosqlbench.api.markdown.types.MarkdownInfo;
import io.nosqlbench.api.spi.BundledApp;
import io.nosqlbench.nb.annotations.Service;
import joptsimple.*;
import java.nio.file.Path;
@ -27,35 +29,15 @@ import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class MarkdownExporter implements Runnable {
@Service(value = BundledApp.class, selector = "markdown-exporter")
public class MarkdownExporter implements BundledApp, Runnable {
public static final String APP_NAME = "exporter";
private final Path basePath;
private final Set<DocScope> scopeSet;
public MarkdownExporter(Path basePath, Set<DocScope> scopeSet) {
this.basePath = basePath;
this.scopeSet = scopeSet;
}
private Path basePath;
private Set<DocScope> scopeSet;
public static void main(String[] args) {
final OptionParser parser = new OptionParser();
OptionSpec<String> basedir = parser.accepts("basedir", "base directory to write to")
.withRequiredArg().ofType(String.class).defaultsTo(".");
OptionSpec<String> docScopes = parser.accepts("scopes", "scopes of documentation to export")
.withRequiredArg().ofType(String.class).defaultsTo(DocScope.ANY.toString());
parser.acceptsAll(List.of("-h","--help","help"),"Display help").forHelp();
OptionSet options = parser.parse(args);
Path basePath = Path.of(basedir.value(options));
Set<DocScope> scopeSet = docScopes.values(options).stream().map(DocScope::valueOf).collect(Collectors.toSet());
new MarkdownExporter(basePath,scopeSet).run();
new MarkdownExporter().appMain(args);
}
@Override
@ -65,4 +47,25 @@ public class MarkdownExporter implements Runnable {
}
@Override
public int appMain(String[] args) {
final OptionParser parser = new OptionParser();
OptionSpec<String> basedir = parser.accepts("basedir", "base directory to write to")
.withRequiredArg().ofType(String.class).defaultsTo(".");
OptionSpec<String> docScopes = parser.accepts("scopes", "scopes of documentation to export")
.withRequiredArg().ofType(String.class).defaultsTo(DocScope.ANY.toString());
parser.acceptsAll(List.of("-h", "--help", "help"), "Display help").forHelp();
OptionSet options = parser.parse(args);
Path basePath = Path.of(basedir.value(options));
Set<DocScope> scopeSet = docScopes.values(options).stream().map(DocScope::valueOf).collect(Collectors.toSet());
this.basePath = basePath;
this.scopeSet = scopeSet;
run();
return 0;
}
}

View File

@ -0,0 +1,21 @@
/*
* Copyright (c) 2022 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.nosqlbench.api.spi;
public interface BundledApp {
int appMain(String[] args);
}

View File

@ -16,6 +16,8 @@
package io.nosqlbench.virtdata.userlibs.apps;
import io.nosqlbench.api.spi.BundledApp;
import io.nosqlbench.nb.annotations.Service;
import io.nosqlbench.virtdata.userlibs.apps.diagnoseapp.VirtDataDiagnoseApp;
import io.nosqlbench.virtdata.userlibs.apps.docsapp.VirtDataGenDocsApp;
import io.nosqlbench.virtdata.userlibs.apps.valuesapp.VirtDataCheckPerfApp;
@ -25,7 +27,8 @@ import java.util.Arrays;
/**
* This just routes the user to the correct sub-app depending on the leading verb, stripping it off in the process.
*/
public class VirtDataMainApp {
@Service(value=BundledApp.class, selector = "virtdata")
public class VirtDataMainApp implements BundledApp {
private final static String APP_TESTMAPPER = "testmapper";
private final static String APP_GENDOCS = "gendocs";
@ -37,9 +40,14 @@ public class VirtDataMainApp {
}
public static void main(String[] args) {
new VirtDataMainApp().appMain(args);
}
@Override
public int appMain(String[] args) {
if (args.length == 0) {
System.out.println("Usage: app (" + APP_TESTMAPPER + "|" + APP_GENDOCS + "|" + APP_DIAGNOSE +")");
return;
return 1;
}
String appSelection = args[0];
@ -57,5 +65,6 @@ public class VirtDataMainApp {
} else {
System.err.println("Error in command line. The first argument must one of " + String.join(",", names));
}
return 0;
}
}