Version: |
org.nasdanika.cli@2025.2.0
|
---|
drawio test-data/jira/diagram.drawio html-app -r test-data/jira/root-action.yml --add-to-root site -r=-1 -F test-data/jira/page-template.yml test-data/jira/docs
drawio test-data/drawio-http/diagram.drawio http-server --http-port=8080 processor route
test-data/drawio-http/diagram.drawio
diagram resource8080
drawio -p my-property="My property" test-data/invocable.drawio invoke 33 66
my-property
to My property
test-data/invocable.drawio
diagram document33
and 66
argumentsThe command loads URI Handlers using the capability framework. You can load resources from Maven with the Maven URI Handler. You can also create and register a custom URI handler, for example GitLabURIHandler to load diagram resources from GitLab. Below is an example of a capability factory:
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.resource.URIHandler;
import org.nasdanika.capability.emf.URIConverterContributorCapabilityFactory;
import org.nasdanika.common.ProgressMonitor;
/**
* Contributes {@link URIHandler} loading from Maven repositories
*/
public class MavenURIHandlerCapabilityFactory extends URIConverterContributorCapabilityFactory {
@Override
protected void contribute(
URIConverter uriConverter,
Loader loader,
ProgressMonitor progressMonitor) {
uriConverter.getURIHandlers().add(0, new MavenURIHandler(loader.getCapabilityLoader(), progressMonitor));
}
}
To contribute a sub-command:
@ParentCommands(Document.Supplier.class)
annotation to your command classDocument.Supplier
and annotate it with @ParentCommand
. You may declare a setter method instead.Document
.as shown in the code snippet below:
import org.nasdanika.cli.ParentCommands;
import org.nasdanika.common.ProgressMonitor;
import org.nasdanika.drawio.Document;
import picocli.CommandLine.Command;
import picocli.CommandLine.ParentCommand;
@Command(...)
@ParentCommands(Document.Supplier.class)
public class MyCommand {
@ParentCommand
private Document.Supplier documentSupplier;
public void myMethod(ProgressMonitor progressMonitor) {
Document document = documentSupplier.getDocument(progressMonitor);
...
}
}
Below is a factory:
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import org.nasdanika.common.ProgressMonitor;
import picocli.CommandLine;
public class MyCommanddFactory extends SubCommandCapabilityFactory<MyCommand> {
@Override
protected Class<MyCommand> getCommandType() {
return MyCommand.class;
}
@Override
protected CompletionStage<MyCommand> doCreateCommand(
List<CommandLine> parentPath,
Loader loader,
ProgressMonitor progressMonitor) {
return CompletableFuture.completedStage(new MyCommand(loader.getCapabilityLoader()));
}
}
The factory shall be registered as a CapabilityFactory provider in module-info.java
:
import org.nasdanika.capability.CapabilityFactory;
module <module name> {
...
opens <package with commands>; // For reflection and documentation resource loading
provides CapabilityFactory with MyCommandFactory;
}
You can create sub-commands which execute diagrams by extending AbstractElementInvocableCommand. invoke is an example of such a command. General purpose executable graphs and diagrams Medium story explains how to create diagram element processors.