1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//! Command-line interface definition.
use std::path::PathBuf;
use clap::{Args, Parser, Subcommand};
/// A Laravel-inspired web framework for Rust.
#[derive(Debug, Parser)]
#[command(name = "slave", version, about, long_about = None)]
#[command(propagate_version = true, arg_required_else_help = true)]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
}
#[derive(Debug, Subcommand)]
pub enum Command {
/// Create a new slave application
New(NewArgs),
/// Create a new model in a domain module
///
/// Writes src/modules/<module>/model.rs. The module defaults to the model
/// name in snake_case (`BlogPost` → `blog_post`) and is created if missing.
#[command(name = "make:model")]
MakeModel(MakeArgs),
/// Create MCP tools for a domain module
///
/// Writes src/modules/<module>/tools.rs with example `<name>_list` and
/// `<name>_get` tools and registers it in src/modules/mod.rs. MCP tools are
/// the application's only business interface. The module defaults to the
/// name without its `Tools` suffix, in snake_case (`BlogPostTools` →
/// `blog_post`).
#[command(name = "make:tools")]
MakeTools(MakeArgs),
/// Create a web app in apps/<name> and route a domain to it
///
/// `--stack axum` (default) renders HTML on the server: light and fast.
/// `--stack dioxus` is a single-page app compiled to WebAssembly, for
/// complex, interactive apps (needs `dx`, the Dioxus CLI). Either way the
/// app gets its data from the MCP backend. It is registered in
/// config/apps.toml, like Laravel's `Route::domain()`, and started by
/// `slave serve`.
#[command(name = "make:app")]
MakeApp(MakeAppArgs),
/// Create a new database migration
///
/// Writes database/migrations/<timestamp>_<name>.rs and registers it in
/// database/migrations/mod.rs. Names like `create_posts_table` start from
/// a CREATE TABLE template; others start empty and irreversible.
#[command(name = "make:migration")]
MakeMigration {
/// Migration name in snake_case, e.g. `create_users_table`
name: String,
},
/// Run all pending database migrations as a new batch
Migrate,
/// Show which migrations have run and which are pending
#[command(name = "migrate:status")]
MigrateStatus,
/// Roll back the most recent batch of migrations
///
/// Refuses, changing nothing, if any migration in the batch is
/// irreversible (its `down()` returns `None`).
#[command(name = "migrate:rollback")]
MigrateRollback,
/// List the domain routes in config/apps.toml and whether each app is up
#[command(name = "route:list")]
RouteList,
/// Show which route, app and headers a host would get
#[command(name = "route:match")]
RouteMatch {
/// Host to look up, e.g. `tokox.localhost`
host: String,
},
/// Run the MCP backend, the domain gateway and every app in apps/
Serve(ServeArgs),
}
#[derive(Debug, Args)]
pub struct NewArgs {
/// Name of the application (also used as the directory and package name)
pub name: String,
/// Depend on a local checkout of slave-framework instead of crates.io
#[arg(long, value_name = "PATH")]
pub framework_path: Option<PathBuf>,
}
#[derive(Debug, Args)]
pub struct MakeArgs {
/// Type name in PascalCase, e.g. `Post` or `PostTools`
pub name: String,
/// Domain module to generate into, in snake_case (default: derived from the name)
#[arg(short, long, visible_alias = "domain", value_name = "MODULE")]
pub module: Option<String>,
/// Overwrite the file with a fresh template if it already exists
#[arg(short, long)]
pub force: bool,
}
#[derive(Debug, Args)]
pub struct MakeAppArgs {
/// App name, used as apps/<name> and its package name, e.g. `dashboard`
pub name: String,
/// Host routed to the app, e.g. `admin.localhost` or `{toko}.localhost`
#[arg(long, value_name = "HOST")]
pub domain: String,
/// Port the app listens on [default: the next free port from 4000]
#[arg(long)]
pub port: Option<u16>,
/// How the app renders
#[arg(long, value_enum, default_value_t = Stack::Axum)]
pub stack: Stack,
}
/// The kind of web app `make:app` creates.
#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)]
pub enum Stack {
/// Server-rendered HTML with Axum: fast, simple pages
Axum,
/// A Dioxus single-page app (WebAssembly): complex, interactive UIs
Dioxus,
}
#[derive(Debug, Args)]
pub struct ServeArgs {
/// Host address for the MCP backend [default: APP_HOST from the environment or .env, else 127.0.0.1]
#[arg(long)]
pub host: Option<String>,
/// Port for the MCP backend [default: APP_PORT from the environment or .env, else 3000]
#[arg(short, long)]
pub port: Option<u16>,
/// Build and run everything in release mode
#[arg(long)]
pub release: bool,
}