Skip to content

Commit

Permalink
Fix up the standalone and CLI command line flags (#148)
Browse files Browse the repository at this point in the history
* Apply the --in-memory flag to the CLI as well

* Correct the CLI vs Standalone switch for which directories to use
  • Loading branch information
kulakowski authored Aug 7, 2023
1 parent b41945e commit 905d206
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions crates/standalone/src/subcommands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ pub fn cli(mode: ProgramMode) -> clap::Command {
.long("jwt-priv-key-path")
.help("The path to the private jwt key for issuing identities (SPACETIMEDB_JWT_PRIV_KEY)");

let in_memory_arg = Arg::new("in_memory")
.long("in-memory")
.action(SetTrue)
.help("Whether to run the database entirely in memory");

// the default root for files, this *should* be the home directory unless it cannot be determined.
let default_root = if let Some(dir) = dirs::home_dir() {
dir
Expand All @@ -76,9 +81,10 @@ pub fn cli(mode: ProgramMode) -> clap::Command {
.unwrap()
.to_string();

// If this isn't standalone, we provide default values
// The CLI defaults to starting in, and getting configuration from, the user's home directory.
// The standalone mode instead uses global directories.
match mode {
ProgramMode::Standalone => {
ProgramMode::CLI => {
log_conf_path_arg = log_conf_path_arg.default_value(format!("{}/.spacetime/log.conf", default_root));
log_dir_path_arg = log_dir_path_arg.default_value(format!("{}/.spacetime", default_root));
database_path_arg = database_path_arg.default_value(format!("{}/.spacetime/stdb", default_root));
Expand All @@ -87,7 +93,7 @@ pub fn cli(mode: ProgramMode) -> clap::Command {
jwt_priv_key_path_arg =
jwt_priv_key_path_arg.default_value(format!("{}/.spacetime/id_ecdsa", default_root));
}
ProgramMode::CLI => {
ProgramMode::Standalone => {
log_conf_path_arg = log_conf_path_arg.default_value("/etc/spacetimedb/log.conf");
log_dir_path_arg = log_dir_path_arg.default_value("/var/log");
database_path_arg = database_path_arg.default_value("/stdb");
Expand All @@ -96,7 +102,7 @@ pub fn cli(mode: ProgramMode) -> clap::Command {
}
}

let mut command = clap::Command::new("start")
clap::Command::new("start")
.about("Starts a standalone SpacetimeDB instance")
.long_about("Starts a standalone SpacetimeDB instance. This command recognizes the following environment variables: \
\n\tSPACETIMEDB_LOG_CONFIG: The path to the log configuration file. \
Expand All @@ -123,21 +129,9 @@ pub fn cli(mode: ProgramMode) -> clap::Command {
.help("Enable Tracy profiling (SPACETIMEDB_TRACY)"),
)
.arg(jwt_pub_key_path_arg)
.arg(jwt_priv_key_path_arg);

// Standalone databases have the option to run entirely in memory.
match mode {
ProgramMode::Standalone => {
let in_memory_arg = Arg::new("in_memory")
.long("in-memory")
.action(SetTrue)
.help("Whether to run the database entirely in memory");
command = command.arg(in_memory_arg);
}
ProgramMode::CLI => (),
};

command.after_help(mode.after_help())
.arg(jwt_priv_key_path_arg)
.arg(in_memory_arg)
.after_help(mode.after_help())
}

/// Sets an environment variable. Print a warning if already set.
Expand Down

0 comments on commit 905d206

Please sign in to comment.