Skip to content

Commit c52c465

Browse files
ajthinkingclaude
andcommitted
Name the commands after the endpoints they are
The first cut invented a second vocabulary: set-property, add-to-property, rename-class, add-use, set-extends. Half of those rename an endpoint that already had a name, which means anyone who knows the PHP API has to learn the CLI's dialect of it too. The directive system was sitting right there and maps onto flags almost exactly. So a command named after an endpoint is now that endpoint. Same arguments, same directives as flags, same result: `archetype property <target> fillable nickname --add` is `$file->add()->property('fillable', 'nickname')`. Give a value and it writes, give none and it reads. property className extends implements namespace use useTrait classConstant methodNames make fillable hidden visible guarded unguarded casts dates table connection timestamps hasOne hasMany belongsTo belongsToMany Operations with names of their own are the ones with no PHP equivalent — inspect, show, find, set-array-key, add-case, the method operations, apply, and the seven relationship types LaravelFile does not cover. The operation map prints in those two halves so the rule is visible rather than documented somewhere else. Two tests hold the line: every operation listed as an endpoint must be a real method on LaravelFile, and `archetype hasMany <target> Task` must produce byte-identical output to `$file->hasMany('Task')`. With no options given the relationship commands call the endpoint rather than reimplementing it. Two bugs fell out of the rewrite, both from reading a value off a file that already carried a directive — the endpoints read directives off the file, so `$file->add()->use()` as a getter appends instead of answering. State is now read from the syntax tree, and directives are applied at the write itself. The second was mine from the first cut: useTrait() answers with Node\Name objects, so class_basename() on them returned "Name" and the already-uses check never matched. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AjUMv5rFTVJMr6F1J7bx7x
1 parent b734d9e commit c52c465

44 files changed

Lines changed: 1925 additions & 1399 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,26 @@ printer and no query builder changes. Everything new lives in `src/Console`.
1313

1414
### Added
1515

16-
- **A command line.** 26 operations, each an Artisan command under `archetype:`,
16+
- **A command line.** Each operation is an Artisan command under `archetype:`,
1717
plus an `archetype` binary that finds the application and forwards to it. Run
1818
`archetype` with no arguments for the list, or see the
1919
[reference](docs.md#command-line-reference).
2020

21-
Reading: `inspect`, `show`, `find`, `errors`.
22-
Writing: `make`, `set-property`, `add-to-property`, `empty-property`,
23-
`remove-property`, `set-casts`, `add-relation`, `set-array-key`, `add-use`,
24-
`remove-use`, `add-trait`, `add-implements`, `set-extends`, `set-namespace`,
25-
`rename-class`, `set-const`, `remove-const`, `add-case`, `add-method`,
26-
`replace-method`, `remove-method`, `apply`.
21+
- **An operation named after an endpoint is that endpoint.** Same arguments, same
22+
directives as flags, same result — `archetype property <target> fillable
23+
nickname --add` is `$file->add()->property('fillable', 'nickname')`. Give a
24+
value and it writes, give none and it reads. Endpoint commands: `property`,
25+
`className`, `extends`, `implements`, `namespace`, `use`, `useTrait`,
26+
`classConstant`, `methodNames`, `make`, the ten `LaravelFile` model properties
27+
(`fillable`, `hidden`, `visible`, `guarded`, `unguarded`, `casts`, `dates`,
28+
`table`, `connection`, `timestamps`) and the four relationships (`hasOne`,
29+
`hasMany`, `belongsTo`, `belongsToMany`).
30+
31+
- **Operations with names of their own, which have no PHP equivalent**:
32+
`inspect`, `show`, `find`, `set-array-key`, `add-case`, `add-method`,
33+
`replace-method`, `remove-method`, `apply`, and the seven relationship types
34+
`LaravelFile` does not cover (`hasOneThrough`, `hasManyThrough`, `morphOne`,
35+
`morphMany`, `morphTo`, `morphToMany`, `morphedByMany`).
2736

2837
- Every operation takes a single target, which is a path, a class name, or a
2938
directory — where a directory means every class beneath it, narrowed with
@@ -36,25 +45,22 @@ printer and no query builder changes. Everything new lives in `src/Console`.
3645
- Every mutation answers with a diff of what it changed, and takes `--dry-run`
3746
to show that diff without writing.
3847
- An operation that cannot act on the construct it was pointed at refuses before
39-
writing anything, rather than writing the part it can. `add-implements`,
40-
`add-trait` and `set-extends` import a name before using it, so a half-done
41-
change would otherwise look like a whole one.
48+
writing anything, rather than writing the part it can. `implements`,
49+
`useTrait` and `extends` import a name before using it, so a half-done change
50+
would otherwise look like a whole one.
4251
- `archetype apply` runs a script of operations in one invocation, reading a file
4352
or standard input.
44-
- `set-casts` writes to whichever casting mechanism a model already uses — the
45-
`casts()` method Laravel 11 generates, or the `$casts` property — instead of
46-
adding a second one beside the first.
4753
- `set-array-key` edits the array a method returns, which is where `rules()`,
4854
`toArray()`, `casts()` and `definition()` keep their contents.
49-
- `add-relation` covers all eleven Eloquent relation types, with pivot tables,
50-
explicit keys, `withPivot`, `withTimestamps` and a custom pivot model.
55+
- `archetype casts` refuses to write `$casts` on a model that declares the
56+
`casts()` method Laravel 11 generates, rather than leaving it with two casting
57+
mechanisms, and points at `set-array-key` instead.
5158

5259
### Known limits
5360

54-
- The property, constant, interface, trait, parent-class and rename operations
55-
work on classes only, because the endpoints they drive address `class`
56-
declarations. On an enum, interface or trait they refuse and write nothing.
57-
`inspect`, `show`, `find`, the method operations, `add-case` and
61+
- The endpoints address `class` declarations, so the endpoint-named operations
62+
work on classes only. On an enum, interface or trait they refuse and write
63+
nothing. `inspect`, `show`, `find`, the method operations, `add-case` and
5864
`set-array-key` have no such limit.
5965

6066
## [2.0.1] - 2026-08-25

0 commit comments

Comments
 (0)