<ContentPage eyebrow="Tutorial" title="Build your executable" description="Check, format, and compile the finished tool.">

<TutorialNavigation slug="tutorial-build" />

Start with chapter 8's `tasks.tea`, `task_list.tea`, and saved `tasks.txt`. There are no source changes in this chapter. We'll check the program, run its tests, and build the executable you've been working toward.

## Check and format

```bash
tea check tasks.tea task_list.tea
tea fmt tasks.tea task_list.tea
tea fmt --check tasks.tea task_list.tea
tea test "$PWD/task_list.tea"
```

The checker should report zero errors and warnings. The formatter may report files it changed; its `--check` invocation should then succeed without requesting changes. The four main walkthrough tests should pass. If you kept the optional test from chapter 8, you'll see five instead.

`tea check` validates source without executing it. Tests exercise behavior, while building also verifies that your program can be linked into a native executable.

## Build and run

```bash
tea build tasks.tea
./bin/tasks list --all
```

The build reports the output at `bin/tasks`; it may mention a cached build. The executable prints:

```text
1. [ ] Learn Tea
2. [x] Build a CLI
3. [x] Take a break
4. [ ] Write a test
```

It reads the same `tasks.txt` because you ran it from the same directory. The entry file imports `task_list.tea`, so Tea compiles that module as part of the program. You don't build the two files separately.

## Use it as a command-line tool

```bash
./bin/tasks add "Build something useful"
./bin/tasks done 1
./bin/tasks list
```

```text
Added task 5.
Completed task 1.
4. [ ] Write a test
5. [ ] Build something useful
```

You can copy the executable to another compatible machine without its Tea source files. Keep platform and architecture in mind: a native executable built for your machine isn't automatically a binary for every operating system. Your data file is separate from the executable, and its location remains relative to the directory where you run the command.

## Check the command's exit status

```bash
./bin/tasks list --unknown
echo $?
```

The tool writes `tasks: invalid arguments; run tasks --help for usage` to standard error, and `echo` prints `2`. Help and successful operations return `0`; malformed saved data or file failures return `1`. Unlike the current script launcher, the compiled executable preserves these exact codes.

## Final source

The complete two-file source is in [Organize and test](/docs/tutorial-test-and-organize). The repository also contains [runnable checkpoints](https://github.com/bentruyman/tea-lang/tree/main/examples/tutorial/tasks) for every source-changing chapter. You can revisit any checkpoint without recreating earlier exercises.

## Try it yourself

Add an `open` command that marks a completed task as open again. Reuse the number validation from `done`, add a test, and update the help text.

<details>
<summary>Design hint</summary>

Extract the “text to valid task index” portion of `complete_task` into a private helper. Have both operations call it, then set the `done` field to the appropriate value. Keep returning whether a task changed so repeating either command doesn't rewrite the file unnecessarily.

</details>

## Where to go next

You started with two lines of Tea and ended with a native tool that owns its data, validates input, handles failures, and has tests. For your next program, reuse the same progression: get a useful result, extract functions when they help, introduce structured data, and test the logic separately from the command interface.

Try a task search command, a different storage location supplied by an argument, or a new CLI entirely. [Browse the examples](/examples) for ideas, use the [language guides](/docs) to deepen your understanding, and keep the [standard-library reference](/reference) nearby.

<TutorialNavigation slug="tutorial-build" position="bottom" />

</ContentPage>
