StructOp Handbook
Contents Examples Commands
Handbook / First steps

Getting started

Install the StructOp command-line tool, then use it to run a program that asks for your name. You’ll use three files and see how a plan becomes a running application.

On this page

Install the tool#

Install the CLI from Downloads and installation. The C examples require a C11 compiler. For Rust, install the Rust toolchain and Cargo. The registry-enabled CLI fetches the declared providers when you run structop init.

Before the first command, read the licence terms and accept them once with structop licence accept. Until you do, every command stops with a hint that says so.

Your first project#

Create a project directory and enter it.

mkdir greeting
cd greeting

Save the following three files there. Start with intent.st, which selects the build target.

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

This intent uses the portable core provider. Change "C" to "Rust" to run the same declarations with Cargo. The default standards are C11 and Rust 2021. After the first structop init, switching between these targets requires only the edit to intent.st.

In vars.st, declare the value that holds the name and the data block that reads it.

vars.st
ability "value" "name" {
    description = "Who to greet"
    type        = String
    initial     = "world"
}

data "value" "name" {
    of = ability.value.name
}

In main.st, ask for a name and print the greeting.

main.st
ability "prompt" "Ask" {
    prompt   = "What is your name"
    response = ability.value.name
}

ability "print" "Greet" {
    message    = "Hello, ${data.value.name.current}!"
    depends_on = [ability.prompt.Ask]
}

Each ability has a kind and a name. Here, the prompt ability named Ask writes to ability.value.name.

The depends_on line makes Greet wait for Ask. Inside the message, ${data.value.name.current} inserts the name the user typed.

Run it#

Run structop init, structop plan and structop apply in the project directory. Enter Ada at the prompt to reproduce this session.

structop
$ 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!

$ structop plan
  # program.app will be created
  + program.app (.structop/build/app)
      + ability.prompt.Ask
      + ability.print.Greet
      + ability.value.name

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

$ structop apply
  # program.app will be created
  + program.app (.structop/build/app)
      + ability.prompt.Ask
      + ability.print.Greet
      + ability.value.name

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

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

What is your name: Ada
Hello, Ada!

$ structop plan
No changes. Your application matches the configuration.
  1. init copies the providers the project names into .structop/providers/ and records their exact versions in .structop/providers.lock.
  2. plan compares the configuration with .structop/state.json and shows what apply would do.
  3. apply writes the selected source file, compiles it, records the new state and runs the program.

The second plan reports no changes; edit main.st and it lists the abilities that changed.

Where the files go#

PathWhat it holds
.structop/build/main.c or .structop/build/main.rsthe generated source for the selected target
.structop/build/appthe compiled program
.structop/state.jsonwhat the last apply built, keyed by resource address
.structop/providers.lockthe exact provider versions this project uses
variables.stvarsvalues for variables (optional)

Next#