MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / exec

Function exec

crates/cli/src/subcommands/dev.rs:145–907  ·  view source on GitHub ↗
(mut config: Config, args: &ArgMatches)

Source from the content-addressed store, hash-verified

143}
144
145pub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::Error> {
146 let project_path = args.get_one::<PathBuf>("project-path").unwrap();
147 let module_path_from_cli = args.get_one::<PathBuf>("module-path");
148 let module_bindings_path = args.get_one::<PathBuf>("module-bindings-path").unwrap();
149 let client_language = args.get_one::<Language>("client-lang");
150 let clear_database = args
151 .get_one::<ClearMode>("clear-database")
152 .copied()
153 .unwrap_or(ClearMode::OnConflict);
154 let force = args.get_flag("force");
155
156 // If you don't specify a server, we default to your default server
157 // If you don't have one of those, we default to "maincloud"
158 let server_from_cli = args.get_one::<String>("server").map(|s| s.as_str());
159
160 let default_server_name = config.default_server_name().map(|s| s.to_string());
161
162 let mut resolved_server = server_from_cli
163 .or(default_server_name.as_deref())
164 .ok_or_else(|| anyhow::anyhow!("Server not specified and no default server configured."))?;
165
166 let cwd = std::env::current_dir()?;
167 let mut project_dir = if project_path.is_absolute() {
168 project_path.clone()
169 } else {
170 cwd.join(project_path)
171 };
172
173 if module_bindings_path.is_absolute() {
174 anyhow::bail!("Module bindings path must be a relative path");
175 }
176 let mut module_bindings_dir = project_dir.join(module_bindings_path);
177
178 let mut spacetimedb_dir = match module_path_from_cli {
179 Some(path) => {
180 if path.is_absolute() {
181 path.clone()
182 } else {
183 std::env::current_dir()?.join(path)
184 }
185 }
186 None => project_dir.join("spacetimedb"),
187 };
188
189 let no_config = args.get_flag("no_config");
190 let skip_publish = args.get_flag("skip_publish");
191 let skip_generate = args.get_flag("skip_generate");
192
193 // --env defaults to "dev" for spacetime dev
194 let env = args.get_one::<String>("env").map(|s| s.as_str()).unwrap_or("dev");
195
196 // Load spacetime.json config early so we can use it for determining project
197 // directories
198 let mut loaded_config = if no_config {
199 None
200 } else {
201 find_and_load_with_env_from(Some(env), project_dir.clone()).with_context(|| "Failed to load spacetime.json")?
202 };

Callers

nothing calls this directly

Calls 15

strip_verbatim_prefixFunction · 0.85
build_publish_schemaFunction · 0.85
find_module_pathFunction · 0.85
generate_database_nameFunction · 0.85
select_databaseFunction · 0.85
detect_client_commandFunction · 0.85
extract_watch_dirsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…