Skip to content

Use cli.toml for default start listen address#4900

Open
0monish wants to merge 1 commit intoclockworklabs:masterfrom
0monish:feature/start-listen-addr-cli-toml
Open

Use cli.toml for default start listen address#4900
0monish wants to merge 1 commit intoclockworklabs:masterfrom
0monish:feature/start-listen-addr-cli-toml

Conversation

@0monish
Copy link
Copy Markdown

@0monish 0monish commented Apr 26, 2026

Description of Changes

This change addresses reviewer feedback on #4576.

As requested by @cloutiertyler, here are the changes:

  • moved the persistent default listen address for spacetime start from project spacetime.json to CLI cli.toml
  • threaded the already-loaded CLI Config into spacetime start instead of introducing a separate project-config lookup in that subcommand
  • preserved precedence so explicit --listen-addr / -l still wins over config, and config still wins over the built-in standalone default
  • documented the setting in the spacetime start CLI reference instead of the standalone runtime-config page

Behavior precedence is now:

  1. Explicit CLI flag, such as spacetime start --listen-addr 127.0.0.1:5000
  2. listen_addr from cli.toml
  3. Built-in standalone default 0.0.0.0:3000

Example:

listen_addr = "0.0.0.0:4000"

With that config in place, spacetime start will bind to 0.0.0.0:4000 unless the user passes --listen-addr explicitly.

Implementation details:

  • added a top-level listen_addr field to the existing CLI config parser and persistence path
  • updated spacetime start to use the loaded CLI config rather than reading project config directly
  • added/kept focused tests for --listen-addr and -l detection so config is only injected when the user did not provide an explicit listen address
  • updated the checked-in CLI reference text for spacetime start

Related:

API and ABI breaking changes

None.

This change does not modify any public API or ABI. It only changes where the CLI reads an optional default value for an existing spacetime start flag.

Expected complexity level and risk

Complexity: 2/5

This is a small, localized CLI behavior change.

The main interaction point is precedence between forwarded CLI args and persisted CLI config. Risk is low because this change:

  • preserves the existing standalone default when listen_addr is absent
  • preserves explicit CLI --listen-addr and -l precedence
  • reuses the existing cli.toml loading path instead of adding another config system

Testing

Completed:

  • cargo fmt --all --check
  • cargo check -p spacetimedb-cli
  • cargo clippy -p spacetimedb-cli --all-targets
  • cargo test -p spacetimedb-cli config::tests --lib
  • cargo test -p spacetimedb-cli subcommands::start::tests --lib

Reviewer checks:

  • Run spacetime start without listen_addr in cli.toml and confirm it still binds to 0.0.0.0:3000
  • Add listen_addr = "0.0.0.0:4000" to cli.toml, run spacetime start, and confirm it binds to 0.0.0.0:4000
  • Run spacetime start --listen-addr 127.0.0.1:5000 with config present and confirm the CLI flag still wins

if s == "-l"
|| (s.starts_with("-l")
&& !s.starts_with("--")
&& s.as_bytes().get(2).is_some_and(|b| !b.is_ascii_alphabetic()))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain this block? at first glance it seems like if s.starts_with("-l") passes, these other checks would as well.

/// - `--listen-addr=<value>`
/// - `-l <value>` (two separate tokens)
/// - `-l<value>` (short flag with attached value, e.g. `-l0.0.0.0:4000`)
fn has_listen_addr_arg(args: impl Iterator<Item = impl AsRef<std::ffi::OsStr>>) -> bool {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function can be removed entirely. if --listen-addr is passed multiple times to spacetimedb-standalone, the last one will be respected.

I would add a comment to this effect when passing --listen-addr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants