mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
improve CLI topic loading
This commit is contained in:
parent
3cbb114d5a
commit
38381e7edb
@ -1,6 +1,8 @@
|
||||
package io.nosqlbench.engine.core;
|
||||
|
||||
import io.nosqlbench.engine.api.activityapi.core.ActivityType;
|
||||
import io.nosqlbench.nb.api.content.Content;
|
||||
import io.nosqlbench.nb.api.content.NBIO;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -19,7 +21,7 @@ public class MarkdownDocInfo {
|
||||
help = new MarkdownDocInfo().forActivityInstance(topic);
|
||||
return Optional.ofNullable(help);
|
||||
} catch (Exception e) {
|
||||
logger.debug("Did not find help topic for activity instance: " + topic);
|
||||
logger.debug("Did not find help topic for activity instance: " + topic);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -34,36 +36,19 @@ public class MarkdownDocInfo {
|
||||
}
|
||||
|
||||
public String forResourceMarkdown(String s, String... additionalSearchPaths) {
|
||||
String docFileName = s + ".md";
|
||||
Optional<Content<?>> docs = NBIO.local()
|
||||
.prefix("docs")
|
||||
.prefix(additionalSearchPaths)
|
||||
.name(s)
|
||||
.extension(".md")
|
||||
.first();
|
||||
|
||||
List<String> searchIn = new ArrayList<>();
|
||||
searchIn.add(docFileName);
|
||||
Arrays.stream(additionalSearchPaths).map(path -> path + docFileName).forEach(searchIn::add);
|
||||
|
||||
logger.info("loading doc file for topic:" + docFileName);
|
||||
|
||||
Optional<InputStream> found = searchIn.stream().map(
|
||||
getClass().getClassLoader()::getResourceAsStream)
|
||||
.filter(Objects::nonNull)
|
||||
.findFirst();
|
||||
|
||||
InputStream stream = found.orElseThrow(
|
||||
() -> new RuntimeException("Unable to find docstream in classpath: " + docFileName)
|
||||
);
|
||||
|
||||
String docInfo = "";
|
||||
try (BufferedReader buffer = new BufferedReader(new InputStreamReader(stream))) {
|
||||
docInfo = buffer.lines().collect(Collectors.joining("\n"));
|
||||
} catch (Throwable t) {
|
||||
throw new RuntimeException("Unable to buffer data from docstream: " + docFileName + ":" + t);
|
||||
}
|
||||
|
||||
return docInfo;
|
||||
return docs.map(Content::asString).orElse(null);
|
||||
}
|
||||
|
||||
public String forActivityInstance(String s) {
|
||||
ActivityType activityType = ActivityType.FINDER.getOrThrow(s);
|
||||
return forResourceMarkdown(activityType.getName()+".md", "docs/");
|
||||
return forResourceMarkdown(activityType.getName() + ".md", "docs/");
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user