Skip to content

Exporters development guide

Two types of exporters

ortfo/db has two types of exporters, with different levels of complexity and expressive power:

YAML exporters
Most of the exporters can be expressed that way. This does not require any development environment setup, but only allows running shell commands.
Go exporters
For more complex exporters, you can write a Go program that implements the Exporter interface. However, for now, Go exporters can only be made available to ortfo by contributing to the project.

YAML exporters

Bootstrapping

You can quickly initialize an example exporter by running

shellsession
ortfodb exporters init my-exporter

Configuration

name

The name of the exporter

description

Some documentation about the exporter

before

Commands to run before the build starts. Go text template that receives .Data

List of Exporter commands

after

Commands to run after the build finishes. Go text template that receives .Data and .Database, the built database.

List of Exporter commands

work

Commands to run during the build, for each work. Go text template that receives .Data and .Work, the current work.

List of Exporter commands

data

Initial data

verbose

If true, will show every command that is run

requires

List of programs that are required to be available in the PATH for the exporter to run.

Exporter command

run
Run a command in a shell
log
Log a message. The first argument is the verb, the second is the color, the third is the message.

Example

As an example, this is the manifest for the built-in SSH exporter

yaml
name: SSH Upload

description: Upload the database to an SSH server using scp or rsync.

requires:
    - scp

data:
    # set to true to only print the commands, not execute them
    dry run: false
    # set to true to enable debugging output for this exporter
    verbose: false
    # set to true to enable rsync
    rsync: true
    # please set this to user@host:/path/to/database.json
    ssh:
after:
    - log:
          - Uploading
          - blue
          - '{{ .Ctx.OutputDatabaseFile }} to [bold]{{ .Data.ssh }} [dim]using{{ if .Data.rsync }} rsync {{ else }} scp {{ end }} [reset]'
    - run: >-
          {{ $from := .Ctx.OutputDatabaseFile }}
          {{ $to := .Data.ssh }}
          {{ if .DryRun }} echo {{end}}
          {{ if .Data.rsync }}
              rsync -r --info=progress {{$from}} {{$to}}
          {{ else }}
              scp {{$from}} {{$to}}
          {{ end }}

Go exporters

See the Go package documentation for the Exporter interface.

Examples

Some examples can be found in ortfo/db's source code: