Skip to content

Commit

Permalink
Fix spacetime server clear (#2055)
Browse files Browse the repository at this point in the history
  • Loading branch information
coolreader18 authored Dec 12, 2024
1 parent 3782f88 commit 10b7c86
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub async fn exec_subcommand(
"list" => list::exec(config, args).await,
"init" => init::exec(config, args).await,
"build" => build::exec(config, args).await.map(drop),
"server" => server::exec(config, args).await,
"server" => server::exec(config, paths, args).await,
"subscribe" => subscribe::exec(config, args).await,
#[cfg(feature = "standalone")]
"start" => start::exec(Some(paths), args).await,
Expand Down
25 changes: 14 additions & 11 deletions crates/cli/src/subcommands/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use crate::{
};
use anyhow::Context;
use clap::{Arg, ArgAction, ArgMatches, Command};
use spacetimedb_standalone::subcommands::start::default_data_dir;
use std::path::PathBuf;
use spacetimedb_paths::{server::ServerDataDir, SpacetimePaths};
use tabled::{
settings::{object::Columns, Alignment, Modify, Style},
Table, Tabled,
Expand Down Expand Up @@ -105,20 +104,24 @@ fn get_subcommands() -> Vec<Command> {
Arg::new("data_dir")
.long("data-dir")
.help("The path to the data directory for the database")
.default_value(default_data_dir().into_os_string())
.value_parser(clap::value_parser!(PathBuf)),
.value_parser(clap::value_parser!(ServerDataDir)),
)
.arg(common_args::yes()),
// TODO: set-name, set-protocol, set-host, set-url
]
}

pub async fn exec(config: Config, args: &ArgMatches) -> Result<(), anyhow::Error> {
pub async fn exec(config: Config, paths: &SpacetimePaths, args: &ArgMatches) -> Result<(), anyhow::Error> {
let (cmd, subcommand_args) = args.subcommand().expect("Subcommand required");
exec_subcommand(config, cmd, subcommand_args).await
exec_subcommand(config, paths, cmd, subcommand_args).await
}

async fn exec_subcommand(config: Config, cmd: &str, args: &ArgMatches) -> Result<(), anyhow::Error> {
async fn exec_subcommand(
config: Config,
paths: &SpacetimePaths,
cmd: &str,
args: &ArgMatches,
) -> Result<(), anyhow::Error> {
match cmd {
"list" => exec_list(config, args).await,
"set-default" => exec_set_default(config, args).await,
Expand All @@ -127,7 +130,7 @@ async fn exec_subcommand(config: Config, cmd: &str, args: &ArgMatches) -> Result
"fingerprint" => exec_fingerprint(config, args).await,
"ping" => exec_ping(config, args).await,
"edit" => exec_edit(config, args).await,
"clear" => exec_clear(config, args).await,
"clear" => exec_clear(config, paths, args).await,
unknown => Err(anyhow::anyhow!("Invalid subcommand: {}", unknown)),
}
}
Expand Down Expand Up @@ -357,11 +360,11 @@ pub async fn exec_edit(mut config: Config, args: &ArgMatches) -> Result<(), anyh
Ok(())
}

async fn exec_clear(_config: Config, args: &ArgMatches) -> Result<(), anyhow::Error> {
async fn exec_clear(_config: Config, paths: &SpacetimePaths, args: &ArgMatches) -> Result<(), anyhow::Error> {
let force = args.get_flag("force");
let data_dir = args.get_one::<PathBuf>("data_dir").unwrap();
let data_dir = args.get_one::<ServerDataDir>("data_dir").unwrap_or(&paths.data_dir);

if data_dir.exists() {
if data_dir.0.exists() {
println!("Database path: {}", data_dir.display());

if !y_or_n(
Expand Down
9 changes: 0 additions & 9 deletions crates/standalone/src/subcommands/start.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::path::PathBuf;
use std::sync::Arc;

use crate::routes::router;
Expand Down Expand Up @@ -56,14 +55,6 @@ impl ProgramMode {
}
}

pub fn default_data_dir() -> PathBuf {
dirs::data_local_dir().unwrap().join(if cfg!(windows) {
"SpacetimeDB/data"
} else {
"spacetime/data"
})
}

pub fn cli(mode: ProgramMode) -> clap::Command {
let jwt_pub_key_path_arg = Arg::new("jwt_pub_key_path")
.long("jwt-pub-key-path")
Expand Down

0 comments on commit 10b7c86

Please sign in to comment.