Skip to main content

decdn_common/cli/
config_cmd.rs

1//! Arguments for the `decdn config` command group (`init`, `validate`).
2
3use std::path::PathBuf;
4
5use clap::{Args, Subcommand};
6
7use super::run::RunArgs;
8
9/// Manage `decdn` configuration files.
10#[derive(Args, Debug)]
11pub struct ConfigArgs {
12    /// The `decdn config` subcommand to run.
13    #[command(subcommand)]
14    pub command: ConfigCommand,
15}
16
17/// Subcommands of `decdn config`.
18#[derive(Subcommand, Debug)]
19pub enum ConfigCommand {
20    /// Write a default configuration file.
21    Init(ConfigInitArgs),
22    /// Validate a configuration file without starting the node.
23    //
24    // Boxed to keep the enum variant size close to `Init`'s — `ConfigValidateArgs`
25    // flattens the large `RunArgs` struct. Mirrors `Command::Run(Box<RunArgs>)`.
26    Validate(Box<ConfigValidateArgs>),
27}
28
29/// Write a default TOML configuration file.
30#[derive(Args, Debug)]
31pub struct ConfigInitArgs {
32    /// Path to write the config file [default: ~/.decdn/node.toml].
33    #[arg(long, value_name = "PATH")]
34    pub output: Option<PathBuf>,
35
36    /// Overwrite existing config file if present.
37    #[arg(long)]
38    pub force: bool,
39
40    /// Deployment to bake in: chain id + contract addresses are filled from the
41    /// shipped deployment manifest so the config runs out of the box. Omit to
42    /// select the only known network; pass `none` for a blank template with
43    /// every address left to fill in.
44    #[arg(long, value_name = "NAME")]
45    pub chain: Option<String>,
46
47    /// Configure an ORIGIN node: write an active `[cache.origin]` pull-through
48    /// backend. Accepts an `http(s)://` base URL (http origin), a `file:///`
49    /// path (fs origin), or `s3` / `s3://<bucket>` (S3-compatible origin —
50    /// bare `s3` leaves a placeholder bucket to edit; either form leaves
51    /// region/endpoint/prefix for the generated comments to walk through).
52    /// Presence of an origin backend is the role signal —
53    /// `cache.relay_foreign_namespaces` then derives to `false` (origin-only).
54    /// Omit for a relay node (no origin; serves foreign content for pay;
55    /// derives to `true`).
56    #[arg(long, value_name = "URL", conflicts_with = "client")]
57    pub origin: Option<String>,
58
59    /// Write a fetch-only CLIENT config: identity + chain coordinates for a
60    /// consumer that fetches and pays (`decdn get`), with none of the
61    /// cache/origin/serving sections a `decdn-node` daemon reads.
62    #[arg(long)]
63    pub client: bool,
64}
65
66/// Validate the resolved configuration without binding ports or connecting to
67/// the RPC endpoint.
68///
69/// Flattens the same argument groups as `decdn-node run` so that `DECDN_*`
70/// environment variables and optional CLI overrides are honored exactly as
71/// they would be during the daemon's startup.
72#[derive(Args, Debug)]
73pub struct ConfigValidateArgs {
74    /// The daemon's own `run` arguments, so validation honors the same
75    /// flags and `DECDN_*` variables startup would.
76    #[command(flatten)]
77    pub run: RunArgs,
78}