-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathlib.rs
More file actions
89 lines (82 loc) · 2.58 KB
/
lib.rs
File metadata and controls
89 lines (82 loc) · 2.58 KB
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
pub mod api;
mod common_args;
mod config;
pub(crate) mod detect;
mod edit_distance;
mod errors;
pub mod spacetime_config;
mod subcommands;
mod tasks;
pub mod util;
pub mod version;
use std::process::ExitCode;
use clap::{ArgMatches, Command};
pub use config::Config;
use spacetimedb_paths::{RootDir, SpacetimePaths};
pub use subcommands::*;
pub use tasks::build;
pub fn get_subcommands() -> Vec<Command> {
vec![
publish::cli(),
delete::cli(),
logs::cli(),
call::cli(),
describe::cli(),
dev::cli(),
sql::cli(),
dns::cli(),
generate::cli(),
list::cli(),
login::cli(),
logout::cli(),
init::cli(),
build::cli(),
server::cli(),
subscribe::cli(),
start::cli(),
lock::cli(),
unlock::cli(),
subcommands::version::cli(),
]
}
pub async fn exec_subcommand(
config: Config,
paths: &SpacetimePaths,
root_dir: Option<&RootDir>,
cmd: &str,
args: &ArgMatches,
) -> anyhow::Result<ExitCode> {
match cmd {
"call" => call::exec(config, args).await,
"describe" => describe::exec(config, args).await,
"dev" => dev::exec(config, args).await,
"publish" => publish::exec(config, args).await,
"delete" => delete::exec(config, args).await,
"logs" => logs::exec(config, args).await,
"sql" => sql::exec(config, args).await,
"rename" => dns::exec(config, args).await,
"generate" => generate::exec(config, args).await,
"list" => list::exec(config, args).await,
"init" => init::exec(config, args).await.map(|_| ()),
"build" => build::exec(config, args).await.map(drop),
"server" => server::exec(config, paths, args).await,
"subscribe" => subscribe::exec(config, args).await,
"start" => return start::exec(paths, args).await,
"login" => login::exec(config, args).await,
"logout" => logout::exec(config, args).await,
"lock" => lock::exec(config, args).await,
"unlock" => unlock::exec(config, args).await,
"version" => return subcommands::version::exec(paths, root_dir, args).await,
unknown => Err(anyhow::anyhow!("Invalid subcommand: {unknown}")),
}
.map(|()| ExitCode::SUCCESS)
}
/// An error type indicating that the process should exit silently with the
/// given `ExitCode`.
#[derive(thiserror::Error, Debug)]
#[error("exit with {0:?}")]
pub struct ExitWithCode(pub ExitCode);
impl ExitWithCode {
/// Basic unsuccessful termination.
pub const FAILURE: Self = ExitWithCode(ExitCode::FAILURE);
}