StructOp Handbook
Contents Examples Commands
Handbook / Build and test

Commands and workflow

A plan shows what will change. Applying it builds the program, records the result so the next plan can identify changes, and then runs the program. When the program builds but fails while running, the result stays recorded: apply exits with the program’s exit status, and the next plan reports no changes. For individual flags, see the command reference.

On this page

The cycle#

a typical session
$ structop init                 # once per project, and after changing providers
$ structop validate             # types, names, references; nothing is written
$ structop plan                 # what apply would change
$ structop apply                # generate code, build, record state, run
$ structop apply -- --verbose 3 # pass arguments to the program

apply always shows the plan first. structop fmt rewrites files in the standard layout and leaves files whose names begin with a dot alone, as the loader does; structop graph draws the run order in the terminal. structop plan lists the abilities of a list in the order the list runs, so a member that waits for a later member is planned after it.

Validation errors#

structop validate reports the first problem with its file, line and column, and suggests the nearest name:

structop validate
Error: unknown component "Playr"; declare it with ability "component" "Playr"
  on main.st line 13, column 20
  Did you mean "Player"?

Resources and state#

A project builds resources, each with an address:

AddressWhat it is
program.appthe selected target’s generated source (main.c or main.rs) and the compiled program
export.NAMEa copy of the program placed where an export block says
intent.st
structop {
    # ...
    export "dist" {
        path = "dist/dungeon-crawler"
    }
}

After each apply, .structop/state.json records what was built. A plan compares the configuration with that record, so it can say why a resource changes, down to the attribute (here, after editing the tour's Sleepy message):

structop plan
  # program.app will be replaced
  ~ program.app (.structop/build/app)
      ~ ability.print.Sleepy
          message: "Shh, ${guest.name} is asleep." -> "Hush, ${guest.name} is asleep."

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

Working with state#

CommandUse it to
structop showprint the recorded state, or a saved plan after checking the file
structop state list, state show ADDRlook at single resources
structop state rm ADDR, state mv FROM TOforget or rename a record without touching files
structop taint ADDR / untaint ADDRforce (or cancel) a rebuild on the next apply
structop apply -replace=ADDRrebuild one resource now
structop refreshre-read the files on disk and record what is there
structop import ADDR PATHadopt an existing file as a configured export
structop plan -out=FILE, apply FILEsave a plan and apply exactly that plan later; it is refused once the project, environment or state has changed
structop destroyremove the program, its exports and the build folder

A lock file (.structop/lock) stops two commands writing state at once.

Environments#

Environments give one configuration separate state and build folders, for example dev and release.

environments
$ structop environment new staging
Created and switched to environment "staging"!
$ structop apply                          # builds into .structop/env/staging/
$ structop plan -environment=default      # look at another one once
$ structop environment select default

default reads variables.stvars; another environment reads that file and then its own NAME.stvars over it. Use environment.name in an expression or ${environment.name} in a string to read the active name. Two environments may not export to the same path.

Testing a project#

structop test runs the run blocks in tests/*.sttest. Each run gets a fresh copy of the project, its own variable values, standard input and arguments, and checks the result:

tests/greeting.sttest
run "says_hello" {
    variables = { Example2_Name = "Ada" }
    input     = "Ada\n"
    expect {
        output_contains = "Hello, Ada"
        exit_code       = 0
    }
}

expect takes output_equals, output_contains, exit_code (0 when left out) or error_contains (validation or the build must fail with that text). See Testing for more.