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
use std::path::PathBuf;
use clap::{Parser, Subcommand, ValueEnum};
#[derive(Debug, Parser)]
#[command(name = "cratestack")]
#[command(about = "CrateStack schema tooling")]
pub(crate) struct Cli {
#[command(subcommand)]
pub(crate) command: Command,
}
#[derive(Debug, Subcommand)]
pub(crate) enum Command {
Check {
#[arg(long)]
schema: PathBuf,
#[arg(long, value_enum, default_value_t = OutputFormat::Human)]
format: OutputFormat,
},
GenerateDart {
#[arg(long)]
schema: PathBuf,
#[arg(long)]
out: PathBuf,
#[arg(long, default_value = "cratestack_client")]
library_name: String,
#[arg(long, default_value = "/api")]
base_path: String,
#[arg(long)]
template_dir: Option<PathBuf>,
},
#[command(name = "generate-typescript", alias = "generate-ts")]
GenerateTypeScript {
#[arg(long)]
schema: PathBuf,
#[arg(long)]
out: PathBuf,
#[arg(long, default_value = "cratestack-client")]
package_name: String,
#[arg(long, default_value = "/api")]
base_path: String,
#[arg(long)]
template_dir: Option<PathBuf>,
},
/// Studio: admin and testing surface for `.cstack` schemas.
Studio {
#[command(subcommand)]
cmd: StudioCmd,
},
PrintIr {
#[arg(long)]
schema: PathBuf,
},
Migrate {
#[command(subcommand)]
action: MigrateAction,
},
}
#[derive(Debug, Subcommand)]
pub(crate) enum StudioCmd {
/// Write a starter `studio.toml` in the chosen directory.
Init {
/// Output directory. The file is always named `studio.toml`.
#[arg(long, default_value = ".")]
out: PathBuf,
/// Overwrite an existing `studio.toml` if present.
#[arg(long)]
force: bool,
},
/// Boot the studio server against a `studio.toml`.
Run {
#[arg(long, default_value = "studio.toml")]
config: PathBuf,
/// Override the bind address (default `127.0.0.1:7878`).
#[arg(long)]
bind: Option<String>,
},
/// Eject a customizable starter project that embeds the studio
/// against your own `.cstack` schemas. The default emits a
/// self-contained binary crate (Cargo.toml, src/main.rs,
/// studio.toml, example schema). Pass `--with-ui` to also drop
/// the Leptos UI sources for front-end customization.
Eject {
#[arg(long)]
out: PathBuf,
/// Optional project name written into Cargo.toml / README.
/// Defaults to the `--out` directory's basename.
#[arg(long)]
name: Option<String>,
/// Overwrite files in `--out` if the directory already exists
/// and has contents.
#[arg(long)]
force: bool,
/// Also unpack the Leptos+Trunk UI sources into `<out>/ui/`
/// for front-end customization.
#[arg(long)]
with_ui: bool,
},
}
#[derive(Debug, Subcommand)]
pub(crate) enum MigrateAction {
/// Generate a migration from `.cstack` vs the committed snapshot.
Diff {
#[arg(long)]
schema: PathBuf,
/// Root directory for per-backend migration trees. Defaults
/// to `migrations/`. Migrations land under
/// `<out_dir>/<backend>/<timestamp>_<name>/`.
#[arg(long, default_value = "migrations")]
out_dir: PathBuf,
/// Which backend(s) to generate for.
#[arg(long, value_enum, default_value_t = MigrateBackendArg::Both)]
backend: MigrateBackendArg,
/// Human-readable slug appended to the migration directory
/// name (e.g. `add_customer_email`). Defaults to `migration`.
#[arg(long, default_value = "migration")]
name: String,
/// Allow the migration to contain lossy ops (DropColumn,
/// DropTable, narrowing type changes). Without this flag,
/// the command refuses to write a destructive migration.
#[arg(long)]
allow_destructive: bool,
},
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, ValueEnum)]
pub(crate) enum MigrateBackendArg {
Postgres,
Sqlite,
Both,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, ValueEnum)]
pub(crate) enum OutputFormat {
Human,
Json,
}