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

Method exec

crates/update/src/cli/self_install.rs:22–103  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

20
21impl SelfInstall {
22 pub fn exec(self) -> anyhow::Result<ExitCode> {
23 let paths = match &self.root_dir {
24 Some(root_dir) => SpacetimePaths::from_root_dir(root_dir),
25 None => SpacetimePaths::platform_defaults()?,
26 };
27
28 let SpacetimePaths {
29 cli_config_dir,
30 cli_bin_file,
31 cli_bin_dir,
32 data_dir,
33 } = &paths;
34
35 let root_dir = self.root_dir.or_else(|| paths.to_root_dir());
36 eprint!("The SpacetimeDB command line tool will now be installed");
37 if let Some(root_dir) = &root_dir {
38 eprintln!(" into {}", root_dir.display());
39 } else {
40 eprintln!(":");
41 eprintln!("\tCLI configuration directory: {}", cli_config_dir.display());
42 eprintln!("\t`spacetime` binary: {}", cli_bin_file.display());
43 eprintln!(
44 "\tdirectory for installed SpacetimeDB versions: {}",
45 cli_bin_dir.display()
46 );
47 eprintln!("\tdatabase directory: {}", data_dir.display());
48 }
49 if !self
50 .yes
51 .confirm_with_default("Would you like to continue?".to_owned(), true)?
52 {
53 eprintln!("Exiting.");
54 return Ok(ExitCode::FAILURE);
55 }
56
57 let current_exe = std::env::current_exe().context("could not get current exe")?;
58 let suppress_eexists = |r: std::io::Result<()>| {
59 r.or_else(|e| (e.kind() == std::io::ErrorKind::AlreadyExists).then_some(()).ok_or(e))
60 };
61 suppress_eexists(cli_bin_dir.create()).context("could not create bin dir")?;
62 suppress_eexists(cli_config_dir.create()).context("could not create config dir")?;
63 suppress_eexists(data_dir.create()).context("could not create data dir")?;
64 cli_bin_file
65 .create_parent()
66 .and_then(|()| std::fs::copy(&current_exe, cli_bin_file))
67 .context("could not install binary")?;
68
69 eprintln!("Downloading latest version...");
70 super::upgrade::Upgrade {}
71 .exec(&paths)
72 .context("failed to download and install latest SpacetimeDB version")?;
73
74 eprintln!(
75 "The `spacetime` command has been installed as {}",
76 cli_bin_file.display()
77 );
78 eprintln!();
79

Callers

nothing calls this directly

Calls 10

to_root_dirMethod · 0.80
confirm_with_defaultMethod · 0.80
create_parentMethod · 0.80
execMethod · 0.65
OkFunction · 0.50
to_ownedMethod · 0.45
kindMethod · 0.45
createMethod · 0.45
unwrapMethod · 0.45
anyMethod · 0.45

Tested by

no test coverage detected