aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/config/mod.rs30
-rw-r--r--src/lib.rs6
2 files changed, 20 insertions, 16 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 7b17f5d..e68b60c 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -1617,7 +1617,7 @@ fn command() -> Command {
with_options(::config::arguments::with_print_config(command), OPTIONS)
}
-/// `continuum node-id FILE`: the node ID of the key in `FILE` (`Loaded::node_id`).
+/// `continuum node-id FILE`: the node ID of the key in `FILE` (`asked_node_id`).
const NODE_ID: &str = "node-id";
/// The configuration, and where each value set came from (absent: default).
@@ -1628,9 +1628,6 @@ pub(crate) struct Loaded {
pub(crate) files: Vec<PathBuf>,
/// `--print-config`: print [`Loaded::report`] and exit.
pub(crate) print_only: bool,
- /// `node-id FILE [--create]`: print the node ID of the key `FILE` holds, made there
- /// with `--create` where there is none, and exit.
- pub(crate) node_id: Option<(PathBuf, bool)>,
}
impl Loaded {
@@ -1700,22 +1697,30 @@ pub(crate) fn load() -> Result<Loaded> {
::config::arguments::refuse_gone(std::env::args().skip(1), &SCHEMA)?;
let matches = command().get_matches();
let print_only = ::config::arguments::prints_config(&matches);
- let node_id = matches.subcommand_matches(NODE_ID).map(|sub| {
- let file = sub.get_one::<String>("file").expect("required");
- (PathBuf::from(file), sub.get_flag("create"))
- });
- if print_only || node_id.is_some() {
- // Logs go to stdout too: the report or the node ID goes there alone (the report
- // says where each value came from anyway).
+ if print_only {
+ // Logs go to stdout too: the report goes there alone (it says where each value
+ // came from anyway).
let _ = crate::logging::set_filter("off");
}
let (merged, files) = merged(&matches, &SCHEMA, &[])?;
let mut loaded = resolve(merged, files)?;
loaded.print_only = print_only;
- loaded.node_id = node_id;
Ok(loaded)
}
+/// `node-id FILE [--create]`, where the command line asks for it: the file whose key's
+/// node ID to print, made there with `--create` where there is none. Asked before
+/// the configuration is read: it needs none of a node's, which a party's founders
+/// don't have yet as they ask for their nodes' IDs.
+pub(crate) fn asked_node_id() -> Option<(PathBuf, bool)> {
+ let matches = command().get_matches();
+ let sub = matches.subcommand_matches(NODE_ID)?;
+ let file = sub.get_one::<String>("file").expect("required");
+ // Logs go to stdout too: the node ID goes there alone.
+ let _ = crate::logging::set_filter("off");
+ Some((PathBuf::from(file), sub.get_flag("create")))
+}
+
/// HyParView's active view, where `neighbours` isn't set: the paper's, for swarms of up
/// to about 10 000 members (its fanout of 4, plus one).
const HYPARVIEW_NEIGHBOURS: usize = 5;
@@ -1821,7 +1826,6 @@ fn resolve(merged: Layer, files: Vec<PathBuf>) -> Result<Loaded> {
.collect(),
files,
print_only: false,
- node_id: None,
})
}
diff --git a/src/lib.rs b/src/lib.rs
index b57f6a5..a420555 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -81,16 +81,16 @@ fn voter(args: &config::Settings) -> Result<Option<federation::held::Voter>> {
pub async fn run() -> Result<()> {
logging::init();
- let config = config::load()?;
- if let Some((file, create)) = &config.node_id {
+ if let Some((file, create)) = config::asked_node_id() {
let new = !file.exists();
- let key = identity::NodeKey::load(file, *create)?;
+ let key = identity::NodeKey::load(&file, create)?;
if new {
eprintln!("a new node key in {}: a new node", file.display());
}
println!("{}", key.id());
return Ok(());
}
+ let config = config::load()?;
if config.print_only {
println!(
"{}",