StructOp Handbook
Contents Examples Commands
Handbook / What is StructOp?

Application development lifecycle

StructOp development follows seven stages. This page explains each one with the real output of the guest list from the guided tour, then follows one change from edit to result.

On this page

The stages#

The StructOp development lifecycleSeven stages in order: Define with .st files, Initialise with structop init, Validate with structop validate, Plan with structop plan, Visualise with structop graph, Apply with structop apply and Test with structop test. A dashed line returns from Test to Define for the next change.Defineedit *.stInitialisestructop initValidatestructop validatePlanstructop planVisualisestructop graphApplystructop applyTeststructop testnext change
The seven stages. A change starts again at Define.

Define the application, initialise its providers, validate the declarations, plan the change, visualise the graph, apply the plan and test the result. Then repeat for the next change.

Define#

Describe application logic, structure, data and behaviour through StructOp declarations. The guest list uses this intent.st and the types.st, vars.st and main.st files from the guided tour, unchanged.

intent.st
structop {
    type_app {
        exec = { lang = "C" }
    }
}

Initialise#

structop init installs the providers the project names into .structop/providers/ and locks their exact versions in .structop/providers.lock, all or none: if one provider is refused, none is installed and no lock is written. Run it once per project and again after changing the provider list.

structop init
$ structop init
Initializing provider plugins...
- Provider index StructOp: serial 7 (verified)
- Installed StructOp/c v2.3.0
- Installed StructOp/rust v2.3.0

StructOp has been successfully initialized!

Validate#

structop validate checks the syntax, types, names and references, and each ability’s attributes against its provider’s schema. It writes nothing.

structop validate
$ structop validate
Success! The configuration is valid.

An error names the file, line and column and suggests the nearest name:

structop validate, with a misspelt reference
$ structop validate
Error: unknown ability "ability.call.Greeet"
  on main.st line 11, column 19
  Did you mean "ability.call.Greet"?

Plan#

structop plan compares the declarations with the state recorded by the last apply and shows what apply would do. Before the first apply there is no state, so everything is to be created.

structop plan
$ structop plan
  # program.app will be created
  + program.app (.structop/build/app)
      + ability.add.Newcomer
      + ability.for.Each
      + ability.call.Greet
      + ability.function.greet
      + ability.switch.Mood
      + ability.print.Happy
      + ability.print.Sleepy
      + ability.enum.Mood
      + ability.struct.Guest
      + ability.value.guests
      + ability.value.i

Plan: 1 to add, 0 to change, 0 to destroy.

Visualise#

structop graph draws the application in the terminal as a flowchart: a box for each ability at the top level, with a count on one that holds others, lines with arrowheads in run order, and labelled lines for what an ability calls, depends on and reads. -depth=N opens N levels of frames around what abilities hold; -format=mermaid, -format=archify and -json give the same graph to other tools. It shows the declared order and dependencies, not everything the program does when it runs.

structop graph
$ structop graph
┌──────────────────────┐             ┌──────────────────────────────┐
│                      │             │                              │
│     add.Newcomer     │◄┄┄┄┄┄┐      │ function.greet (3 abilities) │
│                      │      ┆      │                              │
└───────────┬──────────┘      ┆      └──────────────────────────────┘
            │                 ┆
            │                 ┆
            │            depends on
            │                 ┆
            ▼                 ┆
┌──────────────────────┐      ┆
│                      │      ┆
│ for.Each (1 ability) ├◄─────┼─────reads────────────┐
│                      │      │                      │
└───────────┬──────────┘      │                      │
            │                 │                      │
            │                 │                      │
            │                 │                      │
            │                 │                      │
            ▼                 │                      │
┌──────────────────────┐      │                      │
│                      │      │                      │
│      enum.Mood       │◄┄┄┄┄┄┤                      │
│                      │      │                      │
└───────────┬──────────┘      │                      │
            │                 │                      │
            │                 │                      │
            │            depends on                  │
            │                 │                      │
            ▼                 │                      │
┌──────────────────────┐      │                      │
│                      │      │                      │
│     struct.Guest     ├┄┄┄┄┄┄┤                      │
│                      │      │                      │
└───────────┬──────────┘      │                      │
            │                 │                      │
            │                 │                      │
            │               reads                    │
            │                 │                      │
            ▼                 │                      │
┌──────────────────────┐      │                      │
│                      │      │                      │
│     value.guests     ├──────┼────source────────────┤
│                      │      │                      │
└───────────┬──────────┘      │                      │
            │                 │                      │
            │                 │                      │
            │                 │                      │
            │                 │                      │
            ▼                 │                      ▼
┌──────────────────────┐      │      ┌───────────────┴──────────────┐
│                      │      │      │                              │
│       value.i        │      │      │      data.value.guests       │
│                      │      │      │                              │
└───────────┬──────────┘      │      └──────────────────────────────┘
            │                 │
            │                 │
         source               │
            │                 │
            ▼                 │
┌──────────────────────┐      │
│                      │      │
│     data.value.i     ├──────┘
│                      │
└──────────────────────┘

Unlabelled arrows are the top-level run order. contains, calls and depends on connect abilities; source and reads show which data block a value feeds and who reads it.

Apply#

structop apply prints the plan; when the plan requires a rebuild, it generates the source and compiles it. It then copies any exports, records the new state in .structop/state.json and then runs the program. With -no-run it stops before running; arguments after -- are passed to the program.

structop apply
$ structop apply
  # program.app will be created
  + program.app (.structop/build/app)
      + ability.add.Newcomer
      + ability.for.Each
      + ability.call.Greet
      + ability.function.greet
      + ability.switch.Mood
      + ability.print.Happy
      + ability.print.Sleepy
      + ability.enum.Mood
      + ability.struct.Guest
      + ability.value.guests
      + ability.value.i

Plan: 1 to add, 0 to change, 0 to destroy.

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Welcome, Ada! (36)
Shh, Linus is asleep.
Welcome, Grace! (45)

When nothing has changed, apply builds nothing and still runs the program unless -no-run is given. The state now records the program, its compiler and its providers:

structop state list
$ structop state list
program.app

Test#

structop test runs the run blocks in tests/*.sttest. Each run copies the project to a temporary folder, builds it there with its own variables, input and arguments, runs it and checks the result. The project’s own state is not touched.

tests/guests.sttest
run "counts_guests" {
    expect {
        output_contains = "3 guests are in the treehouse."
    }
}
structop test
$ structop test
tests/guests.sttest
  PASS counts_guests

Success! 1 passed, 0 failed.

A passing test shows that the program produced what the test expects. See Testing.

Change planning in practice#

After the first apply, the guest list is built and recorded, and structop plan reports No changes. Your application matches the configuration. The change below adds one ability that prints how many guests there are, after the loop has greeted them all.

main.st (added at the end)
ability "print" "Count" {
    message    = "${length(data.value.guests.current)} guests are in the treehouse."
    depends_on = [ability.for.Each]
}

A text diff shows five new lines. The plan shows what they mean for the application:

structop plan
$ structop plan
  # program.app will be replaced
  ~ program.app (.structop/build/app)
      + ability.print.Count
      ~ ability.enum.Mood
          (run order): 8 -> 9
      ~ ability.struct.Guest
          (run order): 9 -> 10
      ~ ability.value.guests
          (run order): 10 -> 11
      ~ ability.value.i
          (run order): 11 -> 12

Plan: 0 to add, 1 to change, 0 to destroy.

structop graph -changed draws the application in the terminal, with the new ability marked + and the shifted ones >. The arrows beside print.Count show that it depends on the loop and reads the guest list:

structop graph -changed
$ structop graph -changed
┌──────────────────────┐             ┌──────────────────────────────┐
│                      │             │                              │
│     add.Newcomer     │◄┄┄┄┄┄┐      │ function.greet (3 abilities) │
│                      │      ┆      │                              │
└───────────┬──────────┘      ┆      └──────────────────────────────┘
            │                 ┆
            │                 ┆
            │            depends on
            │                 ┆
            ▼                 ┆
┌──────────────────────┐      ┆
│                      │      ┆
│ for.Each (1 ability) ├◄─────┤
│                      │      │
└───────────┬──────────┘      │
            │                 │
            │                 │
            │            depends on
            │                 │
            ▼                 │
┌──────────────────────┐      │
│                      │      │
│    + print.Count     ├◄─────┼─────reads────────────┐
│                      │      │                      │
└───────────┬──────────┘    reads                    │
            │                 │                      │
            │                 │                      │
            │                 │                      │
            │                 │                      │
            ▼                 │                      │
┌──────────────────────┐      │                      │
│                      │      │                      │
│     > enum.Mood      │◄┄┄┄┄┄┤                      │
│                      │      │                      │
└───────────┬──────────┘      │                      │
            │                 │                      │
            │                 │                      │
            │            depends─on──┐               │
            │                 │      │               │
            ▼                 │      │               │
┌──────────────────────┐      │      │               │
│                      │      │      │               │
│    > struct.Guest    ├┄┄┄┄reads    │               │
│                      │      │      │               │
└───────────┬──────────┘      │      │               │
            │                 │      │               │
            │                 │      │               │
            │                 │      │               │
            │                 │      │               │
            ▼                 │      │               │
┌──────────────────────┐      │      │               │
│                      │      │      │               │
│    > value.guests    ├──────┼────source────────────┤
│                      │      │      │               │
└───────────┬──────────┘      │      │               │
            │                 │      │               │
            │                 │      │               │
            │                 │      └───────────────┤
            │                 │                      │
            ▼                 │                      ▼
┌──────────────────────┐      │      ┌───────────────┴──────────────┐
│                      │      │      │                              │
│      > value.i       │      │      │      data.value.guests       │
│                      │      │      │                              │
└───────────┬──────────┘      │      └──────────────────────────────┘
            │                 │
            │                 │
         source               │
            │                 │
            ▼                 │
┌──────────────────────┐      │
│                      │      │
│     data.value.i     ├──────┘
│                      │
└──────────────────────┘

+ new   > moved

This is the whole drawing StructOp 0.1.0 prints for this change: the abilities at the top level, each with the number of abilities it holds. It shows declared order and dependencies, not everything the program does when it runs. -depth=N opens N levels of frames around what abilities hold, and -format=mermaid and -json give the same graph to other tools.

Applying the change rebuilds the program, records the new state and runs it:

structop apply
$ structop apply
  # program.app will be replaced
  ~ program.app (.structop/build/app)
      + ability.print.Count
      ~ ability.enum.Mood
          (run order): 8 -> 9
      ~ ability.struct.Guest
          (run order): 9 -> 10
      ~ ability.value.guests
          (run order): 10 -> 11
      ~ ability.value.i
          (run order): 11 -> 12

Plan: 0 to add, 1 to change, 0 to destroy.

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

Welcome, Ada! (36)
Shh, Linus is asleep.
Welcome, Grace! (45)
3 guests are in the treehouse.

The state now matches the declarations again, so the next plan has nothing to report:

structop plan
$ structop plan
No changes. Your application matches the configuration.

The same files build as Rust after changing lang in intent.st; the program prints the same four lines and the test passes there too.

What each command does#

CommandBehaviour
structop initInstalls and verifies the providers named in intent.st and locks their versions, or installs none if any is refused.
structop validateChecks the declarations. Writes nothing.
structop planCompares the declarations with the recorded state and prints the changes. Writes nothing unless -out=FILE saves the plan.
structop graphDraws the run order and relationships in the terminal, or prints them as Mermaid, Archify JSON or JSON. -changed and -impact mark what a plan changes and what that can affect.
structop applyPrints the plan, generates and compiles the source when the plan requires a rebuild, copies exports, records state and runs the program unless -no-run is given.
structop testBuilds and runs each test in a temporary copy of the project and compares the result with its expect block.

Every flag is in the command reference, and Commands and workflow covers state, environments and saved plans.