Skip to content

Commit 73f2fc7

Browse files
committed
docs(workspaces): document globs, --workspace, and auto-add member
Cover the three Phase 4 ergonomics features in the workspaces guide and `leo new` reference: glob patterns in `workspace.json` (with the zero-match warning and literal-vs-glob precedence), `leo new --workspace` for scaffolding a workspace skeleton, and the auto-add behavior when `leo new` runs inside a workspace.
1 parent cc8721c commit 73f2fc7

2 files changed

Lines changed: 51 additions & 1 deletion

File tree

documentation/cli/10_new.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@ This command will create a new directory with the given name.
2525

2626
See [Project Layout](./../language/01_layout.md) for more details.
2727

28+
When `leo new <NAME>` is run from inside a [workspace](../guides/03_workspaces.md), the new package is appended to the enclosing `workspace.json` automatically. See [Adding Members](../guides/03_workspaces.md#adding-members) for the exact behavior.
29+
2830
## Flags
2931

3032
### `--library`
3133

3234
Creates a new Leo library instead of a program. A library provides reusable logic that can be imported by other Leo programs or libraries using `leo add --local`, but cannot be deployed or executed on its own. The generated project includes a `tests/` directory with a starter test file.
35+
36+
### `--workspace`
37+
38+
Creates a workspace skeleton instead of a package. The generated directory contains only a `workspace.json` with an empty `members` array; populate it by listing member paths or globs, or by running `leo new` from within the workspace (see [Workspaces](../guides/03_workspaces.md)). Conflicts with `--library`.

documentation/guides/03_workspaces.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ Workspaces are useful when your application is made up of several interacting pr
1212

1313
## Creating a Workspace
1414

15-
Create a `workspace.json` file in your project root. It contains a `members` array listing the relative paths to each member package:
15+
The quickest way to start a workspace is to scaffold one with `leo new`:
16+
17+
```bash
18+
leo new --workspace my_project
19+
```
20+
21+
This creates `my_project/` containing a `workspace.json` with an empty `members` array. The `--workspace` flag is mutually exclusive with `--library` - a workspace is just a root that groups packages, not a package itself, so it has no `src/`, `program.json`, or `tests/` directory.
22+
23+
Equivalently, you can create `workspace.json` by hand in any directory. It contains a `members` array listing the relative paths to each member package:
1624

1725
```json
1826
{
@@ -22,6 +30,42 @@ Create a `workspace.json` file in your project root. It contains a `members` arr
2230

2331
Each entry is a path to a directory containing a standard Leo package with its own `program.json` and `src/main.leo`.
2432

33+
### Glob Members
34+
35+
Entries in `members` can also be glob patterns, resolved relative to the workspace root:
36+
37+
```json
38+
{
39+
"members": ["libraries/core", "programs/*"]
40+
}
41+
```
42+
43+
Standard `glob` syntax is supported, including `*` (matches a single path segment), `**` (matches recursively across directories), `?`, and character classes like `[abc]`. A glob match is included only if the matched directory contains a `program.json`; other matches (files, directories without a manifest, non-UTF-8 paths) are silently skipped.
44+
45+
A glob that matches zero packages logs a warning and continues - it is not an error:
46+
47+
```text
48+
workspace member glob `programs/*` in <root> matched no packages
49+
```
50+
51+
A literal entry pointing at a missing directory still errors, so explicit paths remain strictly validated. Literal entries are resolved before globs and members are deduplicated by canonical path, so a directory matched by both a literal entry and a glob is only included once.
52+
53+
### Adding Members
54+
55+
When `leo new <name>` is run anywhere inside a workspace, the new package's path is appended to the enclosing `workspace.json` automatically and Leo prints:
56+
57+
```text
58+
Added <name> to the enclosing workspace.
59+
```
60+
61+
The append is skipped silently if the new package is already covered by an existing entry - either a literal path equal to the new package's relative path, or a glob that matches it. If the new package ends up outside the discovered workspace root (for example, `leo new ../sibling`), Leo prints a warning and leaves `workspace.json` untouched:
62+
63+
```text
64+
new package at `...` is not inside the discovered workspace root `...`; skipping auto-add
65+
```
66+
67+
Existing `members` order is preserved; new entries are appended at the end. If you would rather not edit `members` by hand at all, use a glob entry such as `programs/*` (see [Glob Members](#glob-members)) - new packages created inside that directory are picked up without modifying `workspace.json`.
68+
2569
## Directory Structure
2670

2771
A typical workspace looks like this:

0 commit comments

Comments
 (0)