Skip to content

feat(cli): add clap CLI with --config flag and listen subcommand#30

Merged
obchain merged 3 commits into
mainfrom
feat/05-clap-cli
Apr 24, 2026
Merged

feat(cli): add clap CLI with --config flag and listen subcommand#30
obchain merged 3 commits into
mainfrom
feat/05-clap-cli

Conversation

@obchain
Copy link
Copy Markdown
Owner

@obchain obchain commented Apr 21, 2026

Closes #6

First runnable binary. charon entrypoint with clap-based argument parsing and two subcommands:

  • listen — placeholder for the scan loop (wired up in later PRs)
  • test-connection --chain <name> — RPC health probe

Structured logging via tracing_subscriber with RUST_LOG override. dotenvy auto-loads .env if present.

Usage:

charon --config config/default.toml listen
charon --config config/default.toml test-connection --chain bnb

Depends on #5 (feat/04-toml-config-loader).

Wire up the first runnable binary. `charon` now accepts:
  --config / -c  (defaults to config/default.toml)
  listen         (subcommand; real scanner arrives in Day 2)

On startup:
  1. dotenvy loads `.env` if present (silent no-op otherwise)
  2. tracing_subscriber configures structured logging
     (RUST_LOG=debug to dial up verbosity)
  3. Cli::parse() validates args via clap derive
  4. Config::load() reads + substitutes + parses TOML; errors bubble
     up with context about which file failed
  5. Successful load logs a one-line summary (chain / protocol /
     flashloan counts, min profit)

Also fix a parser/comment collision in config/default.toml: a doc
comment had a literal \${ENV_VAR} placeholder that the substituter was
picking up as a real env reference. Comment now describes the syntax
in prose.

cargo run -- --config config/default.toml listen now works
end-to-end after \`cp .env.example .env\`.
…xplicit multi-thread flavor

- tracing_subscriber writes to stderr so 'listen' can emit JSON on stdout
  later without interleaving log output into the data stream.
- --config has no default; must come from --config flag or CHARON_CONFIG
  env var. Removes the cwd-relative 'config/default.toml' fallback that
  silently resolves wrong inside the Docker WORKDIR.
- clap workspace feature set adds 'env' so the env = "CHARON_CONFIG" attr
  compiles.
- Annotate the startup info! block with a SECURITY comment enumerating
  the fields that must never appear there (ws_url, http_url, private keys,
  wallet addresses, full Debug of Config / ChainConfig).
- Long-running listen now runs inside tokio::select! with SIGINT (ctrl_c)
  and SIGTERM branches so docker stop → SIGTERM exits cleanly before the
  10 s SIGKILL. wait_sigterm is cfg-gated for non-Unix targets.
- #[tokio::main(flavor = "multi_thread")] makes the concurrency contract
  explicit and immune to future tokio feature-flag trimming.

Closes #82 #83 #84 #85 #86
# Conflicts:
#	Cargo.lock
#	crates/charon-cli/Cargo.toml
@obchain obchain merged commit 92094a6 into main Apr 24, 2026
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.

[cli] clap CLI with --config flag and listen subcommand

1 participant