drawio

Version: org.nasdanika.cli@2025.2.0
Usage: nsd drawio [-fhV] [-b=<baseUri>] [-p=<String=String>]... [-P=URL]... [-u=<String=String>]... [-U=URL of URI to URL mapping resource]... <document> [COMMAND] Loads Drawio document from a URI or file <document> Document URI or file path, resolved relative to the current directory -b, --base-url=<baseUri> Base URI for reolving document and target URIs. Defaults to the current directory URI Resolved relative to the current directory URI -f, --file Document parameter is a file path -h, --help Show this help message and exit. -p, --property=<String=String> Property -P, --properties=URL Properties resource URL relative to the current directory. YAML, JSON, or properties. Type is inferred from the content type header, if it is present, or extension. Properties are loaded in the order of definition, later properties replacing the former -u, --uri=<String=String> URI mapping. Target URIs are resolved relative to the base URI -U, --uris=URL of URI to URL mapping resource URI map resource URL relative to the document file YAML, JSON, or properties Type is inferred from the content type header, if it is present, or extension -V, --version Print version information and exit. Commands:
  • html-app - Generates html application model from a drawio document
  • http-server - Routes HTTP requests to a diagram element processor
  • invoke - Creates an Invocable dynamic proxy from a diagram

Examples

  • 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
    • Loads test-data/drawio-http/diagram.drawio diagram resource
    • Executes html-app sub-command and its site sub-command to generate a documentation site
  • drawio test-data/drawio-http/diagram.drawio http-server --http-port=8080 processor route
    • Loads test-data/drawio-http/diagram.drawio diagram resource
    • Executes http-server sub-command which serves diagram element routes at port 8080
  • drawio -p my-property="My property" test-data/invocable.drawio invoke 33 66
    • Sets property my-property to My property
    • Loads test-data/invocable.drawio diagram document
    • Executes invoke sub-command with 33 and 66 arguments

URI Handlers

The 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));
        
    }
    
}

Contributing sub-commands

To contribute a sub-command:

  • Add @ParentCommands(Document.Supplier.class) annotation to your command class
  • Declare a field of type Document.Supplier and annotate it with @ParentCommand. You may declare a setter method instead.
  • Use the field value to obtain an instance of 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;
    
}

Executable diagrams sub-commands

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.