Skip to content

Commit 2eff9d3

Browse files
committed
feat: add arguments from run cmd to init cmd
1 parent 333f230 commit 2eff9d3

File tree

9 files changed

+234
-8
lines changed

9 files changed

+234
-8
lines changed

crates/data/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ tracing-subscriber.workspace = true
2828
[build-dependencies]
2929
indoc.workspace = true
3030
clap.workspace = true
31+
hypha-network.workspace = true
32+
libp2p.workspace = true
3133
serde.workspace = true
3234
clap-markdown = "0.1.5"

crates/data/src/bin/hypha-data.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ async fn run(config: ConfigWithMetadata<Config>) -> Result<()> {
229229
async fn main() -> miette::Result<()> {
230230
let cli = Cli::parse();
231231
match &cli.command {
232-
Commands::Init {
232+
args @ Commands::Init {
233233
output,
234234
name,
235235
dataset_path,
@@ -251,7 +251,10 @@ async fn main() -> miette::Result<()> {
251251
.with_provider(Serialized::default("dataset_path", dataset_path.clone()));
252252
}
253253

254-
let config = config_builder.build()?.validate()?;
254+
let config = config_builder
255+
.with_provider(Serialized::defaults(&args))
256+
.build()?
257+
.validate()?;
255258

256259
fs::write(output, &to_toml(&config.config).into_diagnostic()?)
257260
.await

crates/data/src/cli.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use std::path::PathBuf;
22

33
use clap::{Parser, Subcommand};
4+
use hypha_network::IpNet;
45
use indoc::indoc;
6+
use libp2p::Multiaddr;
57
use serde::Serialize;
68

79
#[derive(Debug, Parser, Serialize)]
@@ -36,6 +38,7 @@ pub enum Commands {
3638
IMPORTANT: If the output file exists, it will be overwritten without warning.
3739
"}
3840
)]
41+
#[serde(untagged)]
3942
Init {
4043
/// Path where the configuration file will be written
4144
#[clap(short, long, default_value = "config.toml", verbatim_doc_comment)]
@@ -50,6 +53,39 @@ pub enum Commands {
5053
#[clap(short, long("dataset-path"))]
5154
#[serde(skip_serializing_if = "Option::is_none")]
5255
dataset_path: Option<PathBuf>,
56+
57+
/// Gateway addresses to connect to (repeatable, overrides config)
58+
///
59+
/// Gateways provide network bootstrapping, DHT access, and relay functionality.
60+
/// Must include the peer ID in the multiaddr.
61+
///
62+
/// Examples:
63+
/// --gateway /ip4/203.0.113.10/tcp/8080/p2p/12D3KooWAbc...
64+
/// --gateway /dns4/gateway.hypha.example/tcp/443/p2p/12D3KooWAbc...
65+
/// Required: connect to at least one gateway.
66+
#[arg(long("gateway"), verbatim_doc_comment)]
67+
#[serde(skip_serializing_if = "Option::is_none")]
68+
gateway_addresses: Option<Vec<Multiaddr>>,
69+
70+
/// Addresses to listen on (repeatable, overrides config)
71+
///
72+
/// Where the data node accepts incoming connections.
73+
///
74+
/// Examples:
75+
/// --listen /ip4/0.0.0.0/tcp/9092
76+
/// --listen /ip4/0.0.0.0/udp/9092/quic-v1
77+
#[arg(long("listen"), verbatim_doc_comment)]
78+
#[serde(skip_serializing_if = "Option::is_none")]
79+
listen_addresses: Option<Vec<Multiaddr>>,
80+
81+
/// CIDR ranges to exclude from DHT (repeatable, overrides config)
82+
///
83+
/// Filters out peer addresses matching these ranges before adding to the DHT.
84+
///
85+
/// Examples: 10.0.0.0/8, fc00::/7
86+
#[arg(long("exclude-cidr"), verbatim_doc_comment)]
87+
#[serde(skip_serializing_if = "Option::is_none")]
88+
exclude_cidr: Option<Vec<IpNet>>,
5389
},
5490

5591
#[command(

crates/gateway/src/bin/hypha-gateway.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ async fn run(config: ConfigWithMetadata<Config>) -> Result<()> {
160160
async fn main() -> Result<()> {
161161
let cli = Cli::parse();
162162
match &cli.command {
163-
Commands::Init { output, name } => {
163+
args @ Commands::Init { output, name, .. } => {
164164
let mut config_builder =
165165
builder::<Config>().with_provider(Serialized::defaults(&Config::default()));
166166

@@ -173,7 +173,10 @@ async fn main() -> Result<()> {
173173
])));
174174
}
175175

176-
let config = config_builder.build()?.validate()?;
176+
let config = config_builder
177+
.with_provider(Serialized::defaults(&args))
178+
.build()?
179+
.validate()?;
177180

178181
fs::write(output, &to_toml(&config.config).into_diagnostic()?).into_diagnostic()?;
179182

crates/gateway/src/cli.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub enum Commands {
3434
IMPORTANT: If the output file exists, it will be overwritten without warning.
3535
"}
3636
)]
37+
#[serde(untagged)]
3738
Init {
3839
/// Path where the configuration file will be written
3940
#[clap(short, long, default_value = "config.toml", verbatim_doc_comment)]
@@ -43,6 +44,60 @@ pub enum Commands {
4344
#[clap(short, long)]
4445
#[serde(skip_serializing_if = "Option::is_none")]
4546
name: Option<String>,
47+
48+
/// Path to the certificate PEM file (overrides config)
49+
///
50+
/// Must be a valid X.509 certificate in PEM format.
51+
#[arg(long("cert"), verbatim_doc_comment)]
52+
#[serde(skip_serializing_if = "Option::is_none")]
53+
cert_pem: Option<PathBuf>,
54+
55+
/// Path to the private key PEM file (overrides config)
56+
///
57+
/// Must correspond to the certificate. Security: restrict permissions (e.g., chmod 600).
58+
#[arg(long("key"), verbatim_doc_comment)]
59+
#[serde(skip_serializing_if = "Option::is_none")]
60+
key_pem: Option<PathBuf>,
61+
62+
/// Path to the trust chain PEM file (overrides config)
63+
///
64+
/// CA bundle containing certificates trusted by this node. If not provided,
65+
/// uses trust_pem from the configuration file.
66+
#[arg(long("trust"), verbatim_doc_comment)]
67+
#[serde(skip_serializing_if = "Option::is_none")]
68+
trust_pem: Option<PathBuf>,
69+
70+
/// Path to the certificate revocation list PEM (overrides config)
71+
///
72+
/// Optional CRL for rejecting compromised certificates. If not provided,
73+
/// uses crls_pem from the configuration file if present.
74+
#[arg(long("crls"), verbatim_doc_comment)]
75+
#[serde(skip_serializing_if = "Option::is_none")]
76+
crls_pem: Option<PathBuf>,
77+
78+
/// Addresses to listen on (repeatable, overrides config)
79+
///
80+
/// Where this gateway accepts incoming connections.
81+
/// Examples: /ip4/0.0.0.0/tcp/8080, /ip4/0.0.0.0/udp/8080/quic-v1
82+
#[arg(long("listen"), verbatim_doc_comment)]
83+
#[serde(skip_serializing_if = "Option::is_none")]
84+
listen_addresses: Option<Vec<Multiaddr>>,
85+
86+
/// External addresses to advertise (repeatable, overrides config)
87+
///
88+
/// Publicly reachable addresses peers should use to connect.
89+
/// Examples: /ip4/203.0.113.10/tcp/8080, /dns4/gateway.example.com/tcp/8080
90+
#[arg(long("external"), verbatim_doc_comment)]
91+
#[serde(skip_serializing_if = "Option::is_none")]
92+
external_addresses: Option<Vec<Multiaddr>>,
93+
94+
/// CIDR ranges to exclude from DHT (repeatable, overrides config)
95+
///
96+
/// Filters out peer addresses matching these ranges before adding to the DHT.
97+
/// Examples: 10.0.0.0/8, fc00::/7
98+
#[arg(long("exclude-cidr"), verbatim_doc_comment)]
99+
#[serde(skip_serializing_if = "Option::is_none")]
100+
exclude_cidr: Option<Vec<IpNet>>,
46101
},
47102

48103
#[command(

crates/scheduler/src/bin/hypha-scheduler.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,9 @@ async fn get_data_provider(
471471
async fn main() -> Result<()> {
472472
let cli = Cli::parse();
473473
match &cli.command {
474-
Commands::Init { output, name, job } => {
474+
args @ Commands::Init {
475+
output, name, job, ..
476+
} => {
475477
let mut config_builder =
476478
builder::<Config>().with_provider(Serialized::defaults(&Config::default()));
477479

@@ -490,7 +492,10 @@ async fn main() -> Result<()> {
490492
config_builder.with_provider(Serialized::default("scheduler", job));
491493
}
492494

493-
let config = config_builder.build()?.validate()?;
495+
let config = config_builder
496+
.with_provider(Serialized::defaults(&args))
497+
.build()?
498+
.validate()?;
494499

495500
fs::write(output, &to_toml(&config.config)?).into_diagnostic()?;
496501

crates/scheduler/src/cli.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub enum Commands {
3434
IMPORTANT: If the output file exists, it will be overwritten without warning.
3535
"}
3636
)]
37+
#[serde(untagged)]
3738
Init {
3839
/// Path where the configuration file will be written
3940
#[clap(short, long, default_value = "config.toml", verbatim_doc_comment)]
@@ -48,6 +49,54 @@ pub enum Commands {
4849
#[clap(short, long)]
4950
#[serde(skip_serializing_if = "Option::is_none")]
5051
job: Option<String>,
52+
53+
/// Gateway addresses to connect to (repeatable, overrides config)
54+
///
55+
/// Gateways provide network bootstrapping, DHT access, and optional relay.
56+
///
57+
/// Examples:
58+
/// --gateway /ip4/203.0.113.10/tcp/8080/
59+
/// --gateway /dns4/gateway.hypha.example/tcp/443/
60+
#[arg(long("gateway"), verbatim_doc_comment)]
61+
#[serde(skip_serializing_if = "Option::is_none")]
62+
gateway_addresses: Option<Vec<Multiaddr>>,
63+
64+
/// Addresses to listen on (repeatable, overrides config)
65+
///
66+
/// Where the scheduler accepts incoming connections.
67+
///
68+
/// Examples:
69+
/// --listen /ip4/0.0.0.0/tcp/9090
70+
/// --listen /ip4/0.0.0.0/udp/9090/quic-v1
71+
#[arg(long("listen"), verbatim_doc_comment)]
72+
#[serde(skip_serializing_if = "Option::is_none")]
73+
listen_addresses: Option<Vec<Multiaddr>>,
74+
75+
/// External addresses to advertise (repeatable, overrides config)
76+
///
77+
/// Publicly reachable addresses peers should use to connect.
78+
///
79+
/// Examples:
80+
/// --external /ip4/203.0.113.20/tcp/9090
81+
/// --external /dns4/scheduler.example.com/tcp/9090
82+
#[arg(long("external"), verbatim_doc_comment)]
83+
#[serde(skip_serializing_if = "Option::is_none")]
84+
external_addresses: Option<Vec<Multiaddr>>,
85+
86+
/// Enable relay circuit listening via gateway (overrides config)
87+
///
88+
/// true = use relay (default), false = direct connections only.
89+
#[arg(long("relay-circuit"), verbatim_doc_comment)]
90+
#[serde(skip_serializing_if = "Option::is_none")]
91+
relay_circuit: Option<bool>,
92+
93+
/// CIDR ranges to exclude from DHT (repeatable, overrides config)
94+
///
95+
/// Filters out peer addresses matching these ranges before adding to the DHT.
96+
/// Examples: 10.0.0.0/8, fc00::/7
97+
#[arg(long("exclude-cidr"), verbatim_doc_comment)]
98+
#[serde(skip_serializing_if = "Option::is_none")]
99+
exclude_cidr: Option<Vec<IpNet>>,
51100
},
52101

53102
#[command(

crates/worker/src/bin/hypha-worker.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ async fn run(config: ConfigWithMetadata<Config>) -> Result<()> {
277277
async fn main() -> miette::Result<()> {
278278
let cli = Cli::parse();
279279
match &cli.command {
280-
Commands::Init { output, name } => {
280+
args @ Commands::Init { output, name, .. } => {
281281
let mut config_builder =
282282
builder::<Config>().with_provider(Serialized::defaults(&Config::default()));
283283

@@ -290,7 +290,10 @@ async fn main() -> miette::Result<()> {
290290
])));
291291
}
292292

293-
let config = config_builder.build()?.validate()?;
293+
let config = config_builder
294+
.with_provider(Serialized::defaults(&args))
295+
.build()?
296+
.validate()?;
294297

295298
fs::write(output, &to_toml(&config.config).into_diagnostic()?).into_diagnostic()?;
296299

crates/worker/src/cli.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub enum Commands {
4141
IMPORTANT: If the output file exists, it will be overwritten without warning.
4242
"}
4343
)]
44+
#[serde(untagged)]
4445
Init {
4546
/// Path where the configuration file will be written
4647
#[clap(short, long, default_value = "config.toml", verbatim_doc_comment)]
@@ -50,6 +51,75 @@ pub enum Commands {
5051
#[clap(short, long)]
5152
#[serde(skip_serializing_if = "Option::is_none")]
5253
name: Option<String>,
54+
55+
/// Gateway addresses to connect to (repeatable, overrides config)
56+
///
57+
/// Gateways provide network bootstrapping, DHT access, and optional relay.
58+
/// Must include the peer ID in the multiaddr.
59+
///
60+
/// Examples:
61+
/// --gateway /ip4/203.0.113.10/tcp/8080/p2p/12D3KooWAbc...
62+
/// --gateway /dns4/gateway.hypha.example/tcp/443/p2p/12D3KooWAbc...
63+
/// Required: connect to at least one gateway.
64+
#[arg(long("gateway"), verbatim_doc_comment)]
65+
#[serde(skip_serializing_if = "Option::is_none")]
66+
gateway_addresses: Option<Vec<Multiaddr>>,
67+
68+
/// Addresses to listen on (repeatable, overrides config)
69+
///
70+
/// Where the worker accepts incoming connections.
71+
///
72+
/// Examples:
73+
/// --listen /ip4/0.0.0.0/tcp/9091
74+
/// --listen /ip4/0.0.0.0/udp/9091/quic-v1
75+
#[arg(long("listen"), verbatim_doc_comment)]
76+
#[serde(skip_serializing_if = "Option::is_none")]
77+
listen_addresses: Option<Vec<Multiaddr>>,
78+
79+
/// External addresses to advertise (repeatable, overrides config)
80+
///
81+
/// Publicly reachable addresses peers should use to connect.
82+
///
83+
/// Examples:
84+
/// --external /ip4/203.0.113.30/tcp/9091
85+
/// --external /dns4/worker.example.com/tcp/9091
86+
#[arg(long("external"), verbatim_doc_comment)]
87+
#[serde(skip_serializing_if = "Option::is_none")]
88+
external_addresses: Option<Vec<Multiaddr>>,
89+
90+
/// Enable relay circuit listening via gateway (overrides config)
91+
///
92+
/// true = use relay (default), false = direct connections only.
93+
#[arg(long("relay-circuit"), verbatim_doc_comment)]
94+
#[serde(skip_serializing_if = "Option::is_none")]
95+
relay_circuit: Option<bool>,
96+
97+
/// Socket path for driver communication (overrides config)
98+
///
99+
/// Unix domain socket for worker-executor communication (optional).
100+
#[arg(long("socket"), verbatim_doc_comment)]
101+
#[serde(skip_serializing_if = "Option::is_none")]
102+
socket_address: Option<PathBuf>,
103+
104+
/// Base directory for job working directories (overrides config)
105+
///
106+
/// Where per-job working directories are created.
107+
///
108+
/// Examples:
109+
/// --work-dir /tmp
110+
/// --work-dir /mnt/fast-ssd/hypha
111+
#[arg(long("work-dir"), verbatim_doc_comment)]
112+
#[serde(skip_serializing_if = "Option::is_none")]
113+
work_dir: Option<PathBuf>,
114+
115+
/// CIDR ranges to exclude from DHT (repeatable, overrides config)
116+
///
117+
/// Filters out peer addresses matching these ranges before adding to the DHT.
118+
///
119+
/// Examples: 10.0.0.0/8, fc00::/7
120+
#[arg(long("exclude-cidr"), verbatim_doc_comment)]
121+
#[serde(skip_serializing_if = "Option::is_none")]
122+
exclude_cidr: Option<Vec<IpNet>>,
53123
},
54124

55125
#[command(

0 commit comments

Comments
 (0)