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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
use cobble::commands;
use cobble::commands::{DoctorOptions, InspectOptions};
use clap::{Parser, Subcommand};
use std::path::PathBuf;
#[derive(Parser, Debug)]
#[command(name = "cobble")]
#[command(about = "Cobble - Minecraft Data Pack Transpiler", long_about = None)]
#[command(version)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand, Debug)]
enum Commands {
/// Initialize a new Cobble project
Init {
/// Project name (defaults to current directory name)
#[arg(long)]
name: Option<String>,
/// Set the project description
#[arg(long)]
description: Option<String>,
/// Set the pack format version (default: 101.1 for Minecraft Java Edition 26.1.2)
#[arg(long)]
pack_format: Option<String>,
/// Project template: minimal, stdlib, or validation
#[arg(long, default_value = "stdlib")]
template: String,
},
/// Build the data pack
Build {
/// Input file or directory (defaults to src/ if cobble.toml exists)
input: Option<PathBuf>,
/// Output directory
#[arg(short, long)]
output: Option<PathBuf>,
/// Override the namespace
#[arg(long)]
namespace: Option<String>,
/// Override pack format version (default: 101.1 for Minecraft Java Edition 26.1.2)
#[arg(long)]
pack_format: Option<String>,
/// Override pack description
#[arg(long)]
description: Option<String>,
/// Show verbose output
#[arg(short, long)]
verbose: bool,
/// Suppress successful build progress and summary output
#[arg(short, long)]
quiet: bool,
/// Create a zip file
#[arg(long)]
zip: bool,
/// Validate generated .mcfunction files after building
#[arg(long)]
validate: bool,
/// Compile and summarize without writing final output
#[arg(long)]
dry_run: bool,
/// Path to commands.json (default data/commands.json is auto-generated if missing)
#[arg(long, default_value = "data/commands.json")]
commands_json: PathBuf,
},
/// Watch for changes and rebuild automatically
Watch {
/// Input file or directory to watch
input: Option<PathBuf>,
/// Output directory
#[arg(short, long)]
output: Option<PathBuf>,
/// Data pack namespace
#[arg(long)]
namespace: Option<String>,
/// Pack format version (currently requires 101.1)
#[arg(long)]
pack_format: Option<String>,
/// Data pack description
#[arg(long)]
description: Option<String>,
/// Verbose output
#[arg(short, long)]
verbose: bool,
/// Create a zip file
#[arg(long)]
zip: bool,
/// Validate generated .mcfunction files after each successful build
#[arg(long)]
validate: bool,
/// Path to commands.json (default data/commands.json is auto-generated if missing)
#[arg(long, default_value = "data/commands.json")]
commands_json: PathBuf,
},
/// Check syntax without building
Check {
/// Input file or directory to check
input: Option<PathBuf>,
},
/// Report Cobble project and validation environment status
Doctor {
/// Project path to inspect (defaults to current directory)
path: Option<PathBuf>,
/// Path to commands.json to inspect
#[arg(long, default_value = "data/commands.json")]
commands_json: PathBuf,
},
/// Inspect Cobble metadata in a generated data pack directory
Inspect {
/// Generated data pack directory to inspect
input: PathBuf,
/// Print machine-readable JSON
#[arg(long)]
json: bool,
},
/// Validate generated .mcfunction files against Minecraft's command tree
Validate {
/// Datapack directory to validate (output from build)
input: PathBuf,
/// Path to commands.json (default data/commands.json is auto-generated if missing)
#[arg(long, default_value = "data/commands.json")]
commands_json: PathBuf,
},
}
fn main() {
let cli = Cli::parse();
let result = match cli.command {
Commands::Init {
name,
description,
pack_format,
template,
} => commands::init(commands::init::InitOptions {
name,
description,
pack_format,
template,
}),
Commands::Build {
input,
output,
namespace,
pack_format,
description,
verbose,
quiet,
zip,
validate,
dry_run,
commands_json,
} => commands::build(commands::build::BuildOptions {
input,
output,
namespace,
pack_format,
description,
verbose,
quiet,
zip,
validate,
dry_run,
commands_json,
}),
Commands::Watch {
input,
output,
namespace,
pack_format,
description,
verbose,
zip,
validate,
commands_json,
} => commands::watch(
input,
output,
namespace,
pack_format,
description,
verbose,
zip,
validate,
commands_json,
),
Commands::Check { input } => commands::check(input),
Commands::Doctor {
path,
commands_json,
} => commands::doctor(DoctorOptions {
path,
commands_json,
}),
Commands::Inspect { input, json } => commands::inspect(InspectOptions { input, json }),
Commands::Validate {
input,
commands_json,
} => commands::validate(commands::validate::ValidateOptions {
input,
commands_json,
}),
};
if let Err(e) = result {
eprintln!("Error: {}", e);
std::process::exit(1);
}
}