node: Remove redudnant CLI options
When an option is available as part of the node configuration (`config.json`), we remove it from the CLI options of `radicle-node`. Instead, we allow a different config file to be specified via the `--config` option.
This commit is contained in:
parent
c7400e894f
commit
9f5ada5fa9
|
|
@ -1,19 +1,15 @@
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::{env, fs, net, process};
|
use std::{env, fs, net, path::PathBuf, process};
|
||||||
|
|
||||||
use anyhow::{anyhow, Context};
|
use anyhow::Context;
|
||||||
use crossbeam_channel as chan;
|
use crossbeam_channel as chan;
|
||||||
use cyphernet::addr::PeerAddr;
|
|
||||||
use localtime::LocalDuration;
|
|
||||||
|
|
||||||
use radicle::node;
|
|
||||||
use radicle::prelude::Signer;
|
use radicle::prelude::Signer;
|
||||||
use radicle::profile;
|
use radicle::profile;
|
||||||
use radicle::version;
|
use radicle::version;
|
||||||
use radicle_node::crypto::ssh::keystore::{Keystore, MemorySigner};
|
use radicle_node::crypto::ssh::keystore::{Keystore, MemorySigner};
|
||||||
use radicle_node::prelude::{Address, NodeId};
|
|
||||||
use radicle_node::Runtime;
|
use radicle_node::Runtime;
|
||||||
use radicle_node::{logger, service, signals};
|
use radicle_node::{logger, signals};
|
||||||
|
|
||||||
pub const NAME: &str = "radicle-node";
|
pub const NAME: &str = "radicle-node";
|
||||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
@ -25,48 +21,38 @@ Usage
|
||||||
radicle-node [<option>...]
|
radicle-node [<option>...]
|
||||||
|
|
||||||
If you're running a public seed node, make sure to use `--listen` to bind a listening socket to
|
If you're running a public seed node, make sure to use `--listen` to bind a listening socket to
|
||||||
eg. `0.0.0.0:8776`, and `--external-address` to advertize your public/external address to the
|
eg. `0.0.0.0:8776`, and add your external addresses in your configuration.
|
||||||
network.
|
|
||||||
|
|
||||||
Options
|
Options
|
||||||
|
|
||||||
--connect <peer> Connect to the given peer address on start
|
--config <path> Config file to use (default ~/.radicle/config.json)
|
||||||
--external-address <address> Publicly accessible address (may be specified multiple times)
|
|
||||||
--git-daemon <address> Address to bind git-daemon to (default 0.0.0.0:9418)
|
--git-daemon <address> Address to bind git-daemon to (default 0.0.0.0:9418)
|
||||||
--tracking-policy (track|block) Default tracking policy
|
|
||||||
--tracking-scope (trusted|all) Default scope for tracking policies
|
|
||||||
--force Force start even if an existing control socket is found
|
--force Force start even if an existing control socket is found
|
||||||
--help Print help
|
|
||||||
--listen <address> Address to listen on
|
--listen <address> Address to listen on
|
||||||
--version Print program version
|
--version Print program version
|
||||||
|
--help Print help
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Options {
|
struct Options {
|
||||||
daemon: Option<net::SocketAddr>,
|
daemon: Option<net::SocketAddr>,
|
||||||
|
config: Option<PathBuf>,
|
||||||
listen: Vec<net::SocketAddr>,
|
listen: Vec<net::SocketAddr>,
|
||||||
force: bool,
|
force: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Options {
|
impl Options {
|
||||||
fn from_env(config: &mut node::Config) -> Result<Self, anyhow::Error> {
|
fn from_env() -> Result<Self, anyhow::Error> {
|
||||||
use lexopt::prelude::*;
|
use lexopt::prelude::*;
|
||||||
|
|
||||||
let mut parser = lexopt::Parser::from_env();
|
let mut parser = lexopt::Parser::from_env();
|
||||||
let mut listen = Vec::new();
|
let mut listen = Vec::new();
|
||||||
let mut daemon = None;
|
let mut daemon = None;
|
||||||
|
let mut config = None;
|
||||||
let mut force = false;
|
let mut force = false;
|
||||||
|
|
||||||
while let Some(arg) = parser.next()? {
|
while let Some(arg) = parser.next()? {
|
||||||
match arg {
|
match arg {
|
||||||
Long("connect") => {
|
|
||||||
let peer: PeerAddr<NodeId, Address> = parser.value()?.parse()?;
|
|
||||||
config.connect.insert(peer.into());
|
|
||||||
}
|
|
||||||
Long("external-address") => {
|
|
||||||
let addr = parser.value()?.parse()?;
|
|
||||||
config.external_addresses.push(addr);
|
|
||||||
}
|
|
||||||
Long("force") => {
|
Long("force") => {
|
||||||
force = true;
|
force = true;
|
||||||
}
|
}
|
||||||
|
|
@ -74,29 +60,10 @@ impl Options {
|
||||||
let addr = parser.value()?.parse()?;
|
let addr = parser.value()?.parse()?;
|
||||||
daemon = Some(addr);
|
daemon = Some(addr);
|
||||||
}
|
}
|
||||||
Long("tracking-policy") => {
|
Long("config") => {
|
||||||
let policy = parser
|
let value = parser.value()?;
|
||||||
.value()?
|
let path = PathBuf::from(value);
|
||||||
.parse()
|
config = Some(path);
|
||||||
.map_err(|s| anyhow!("unknown tracking policy {:?}", s))?;
|
|
||||||
config.policy = policy;
|
|
||||||
}
|
|
||||||
Long("tracking-scope") => {
|
|
||||||
let scope = parser
|
|
||||||
.value()?
|
|
||||||
.parse()
|
|
||||||
.map_err(|s| anyhow!("unknown tracking scope {:?}", s))?;
|
|
||||||
config.scope = scope;
|
|
||||||
}
|
|
||||||
Long("limit-routing-max-age") => {
|
|
||||||
let secs: u64 = parser.value()?.parse()?;
|
|
||||||
config.limits.routing_max_age = LocalDuration::from_secs(secs);
|
|
||||||
}
|
|
||||||
Long("limit-routing-max-size") => {
|
|
||||||
config.limits.routing_max_size = parser.value()?.parse()?;
|
|
||||||
}
|
|
||||||
Long("limit-fetch-concurrency") => {
|
|
||||||
config.limits.fetch_concurrency = parser.value()?.parse()?;
|
|
||||||
}
|
}
|
||||||
Long("listen") => {
|
Long("listen") => {
|
||||||
let addr = parser.value()?.parse()?;
|
let addr = parser.value()?.parse()?;
|
||||||
|
|
@ -114,17 +81,11 @@ impl Options {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.external_addresses.len() > service::ADDRESS_LIMIT {
|
|
||||||
anyhow::bail!(
|
|
||||||
"external address limit ({}) exceeded",
|
|
||||||
service::ADDRESS_LIMIT,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
daemon,
|
daemon,
|
||||||
force,
|
force,
|
||||||
listen,
|
listen,
|
||||||
|
config,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -133,8 +94,7 @@ fn execute() -> anyhow::Result<()> {
|
||||||
logger::init(log::Level::Debug)?;
|
logger::init(log::Level::Debug)?;
|
||||||
|
|
||||||
let home = profile::home()?;
|
let home = profile::home()?;
|
||||||
let mut config = profile::Config::load(&home.config())?.node;
|
let options = Options::from_env()?;
|
||||||
let options = Options::from_env(&mut config)?;
|
|
||||||
|
|
||||||
log::info!(target: "node", "Starting node..");
|
log::info!(target: "node", "Starting node..");
|
||||||
log::info!(target: "node", "Version {} ({})", env!("CARGO_PKG_VERSION"), env!("GIT_HEAD"));
|
log::info!(target: "node", "Version {} ({})", env!("CARGO_PKG_VERSION"), env!("GIT_HEAD"));
|
||||||
|
|
@ -146,6 +106,8 @@ fn execute() -> anyhow::Result<()> {
|
||||||
|
|
||||||
log::info!(target: "node", "Node ID is {}", signer.public_key());
|
log::info!(target: "node", "Node ID is {}", signer.public_key());
|
||||||
|
|
||||||
|
let config = options.config.unwrap_or_else(|| home.config());
|
||||||
|
let config = profile::Config::load(&config)?.node;
|
||||||
let proxy = net::SocketAddr::new(net::Ipv4Addr::LOCALHOST.into(), 9050);
|
let proxy = net::SocketAddr::new(net::Ipv4Addr::LOCALHOST.into(), 9050);
|
||||||
let daemon = options.daemon.unwrap_or_else(|| {
|
let daemon = options.daemon.unwrap_or_else(|| {
|
||||||
net::SocketAddr::new(net::Ipv4Addr::LOCALHOST.into(), radicle::git::PROTOCOL_PORT)
|
net::SocketAddr::new(net::Ipv4Addr::LOCALHOST.into(), radicle::git::PROTOCOL_PORT)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue