aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config/mod.rs22
-rw-r--r--src/federation/party.rs10
2 files changed, 26 insertions, 6 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 6f9bd98..430ace1 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -28,7 +28,9 @@ use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue;
use tracing::{info, warn};
-pub(crate) use ::config::arguments::{merged, with_options};
+#[cfg(test)]
+pub(crate) use ::config::arguments::merged;
+pub(crate) use ::config::arguments::with_options;
pub(crate) use ::config::layer::read;
pub(crate) use ::config::layer::{Layer, Origin, Provenance};
pub(crate) use ::config::option::{Kind, OptionSpec, Schema, option};
@@ -1719,18 +1721,29 @@ impl Loaded {
}
}
+/// The command line as the command reads it, and the importers it names
+/// (`--meta-importer-NAME`), which are taken off first: their names are the
+/// configuration's, not the command's. Exits on `--help`, `--version` and syntax errors.
+fn command_line() -> Result<(clap::ArgMatches, ::config::import::Importers)> {
+ let mut arguments = std::env::args();
+ let program = arguments.next().unwrap_or_else(|| "continuum".to_owned());
+ let (arguments, named) = ::config::arguments::take_importers(arguments)?;
+ let matches = command().get_matches_from(std::iter::once(program).chain(arguments));
+ Ok((matches, named))
+}
+
/// Reads the command line and the configuration files it names. Exits on `--help`,
/// `--version` and command-line syntax errors, like any command.
pub(crate) fn load() -> Result<Loaded> {
::config::arguments::refuse_gone(std::env::args().skip(1), &SCHEMA)?;
- let matches = command().get_matches();
+ let (matches, named) = command_line()?;
let print_only = ::config::arguments::prints_config(&matches);
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 (merged, files) = ::config::arguments::merged_in(&matches, &SCHEMA, &[], &named)?;
let mut loaded = resolve(merged, files)?;
loaded.print_only = print_only;
Ok(loaded)
@@ -1741,7 +1754,8 @@ pub(crate) fn load() -> Result<Loaded> {
/// 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();
+ // An importer named amiss is said where the configuration is read (`load`).
+ let (matches, _) = command_line().ok()?;
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.
diff --git a/src/federation/party.rs b/src/federation/party.rs
index eaf28b5..17e3f0e 100644
--- a/src/federation/party.rs
+++ b/src/federation/party.rs
@@ -627,7 +627,13 @@ fn begin_federation(dir: &Path, matches: &ArgMatches) -> Result<()> {
/// Runs the client, as its arguments say.
pub(crate) async fn main() -> Result<()> {
- let matches = command().get_matches();
+ // The importers it names, off the command line first: their names are its own.
+ let mut arguments = std::env::args();
+ let program = arguments
+ .next()
+ .unwrap_or_else(|| "continuum-party".to_owned());
+ let (arguments, named) = ::config::arguments::take_importers(arguments)?;
+ let matches = command().get_matches_from(std::iter::once(program).chain(arguments));
let (name, sub) = matches.subcommand().expect("a subcommand is required");
// Those that use no options read no federation's.
let dir = if matches!(name, "twice" | "root" | "judge" | "found") {
@@ -651,7 +657,7 @@ pub(crate) async fn main() -> Result<()> {
.map(|dir| dir.join("party.toml"))
.filter(|file| file.exists())
.collect();
- let (merged, _) = config::merged(&matches, &config::PARTY, &first)?;
+ let (merged, _) = ::config::arguments::merged_in(&matches, &config::PARTY, &first, &named)?;
let mut options: Options = config::read(&merged)?;
// In a federation's directory, its record and key, where none other is named.
if let Some(dir) = &dir {