1mod apple;
4mod args;
5mod build;
6mod compression;
7mod native_dev;
8mod process;
9mod project;
10mod scaffold;
11mod serve;
12#[cfg(test)]
13mod test_support;
14
15use std::path::Path;
16use std::process::ExitCode;
17
18type Result<T> = std::result::Result<T, String>;
19
20pub fn run_from_manifest(manifest: impl AsRef<Path>) -> ExitCode {
24 let args = match args::Args::parse(std::env::args_os().skip(1)) {
25 Ok(args) => args,
26 Err(error) => {
27 eprintln!("glory: {error}");
28 return ExitCode::FAILURE;
29 }
30 };
31 match execute(manifest.as_ref(), args) {
32 Ok(()) => ExitCode::SUCCESS,
33 Err(error) => {
34 eprintln!("glory: {error}");
35 ExitCode::FAILURE
36 }
37 }
38}
39
40fn execute(manifest: &Path, args: args::Args) -> Result<()> {
41 let manifest = args.manifest.as_deref().unwrap_or(manifest);
42 if args.command == args::Command::Help {
43 println!("{}", args::HELP);
44 return Ok(());
45 }
46 if args.command == args::Command::Version {
47 println!("glory-cli {}", env!("CARGO_PKG_VERSION"));
48 return Ok(());
49 }
50 if args.command == args::Command::Init {
51 return scaffold::init(manifest, args.force, args.cli_path.as_deref());
52 }
53 let project = project::Project::load(manifest, &args)?;
54 match args.command {
55 args::Command::Doctor => project.doctor(),
56 args::Command::Print => project.print(&args),
57 args::Command::Build => build::build(&project, &args).map(|_| ()),
58 args::Command::Bundle => build::bundle(&project, &args),
59 args::Command::Run => build::run(&project, &args),
60 args::Command::Serve => serve::serve(project, args),
61 args::Command::Check => project.check(&args),
62 args::Command::Fmt => project.format(&args),
63 _ => unreachable!(),
64 }
65}