Skip to main content

parse_changes

Function parse_changes 

Source
pub fn parse_changes<I, S>(args: I) -> Result<Vec<Change>, ParseChangeError>
where I: IntoIterator<Item = S>, S: AsRef<str>,
Expand description

Parses --set path=value arguments into configuration changes, typed by the schema in stratum-node-config.

Each argument is split at its first =. The path must name a schema field, and the value is read according to that field’s type:

  • boolean: true or false;
  • integer: a decimal integer, optionally negative (the node checks the range);
  • string, enum and secret reference: the text as given, which may be empty;
  • list of strings: comma-separated elements (a,b), or the same path given in several --set arguments, whose elements are concatenated in order. An empty value (path=) is the empty list. Elements cannot be empty and cannot contain a comma.

Changes come out in the order their paths first appear; the node applies them in schema order regardless.

§Examples

use stratum_node_cli::parse_changes;
use stratum_node_config::Value;

let changes = parse_changes([
    "node.name=alpha",
    "limits.max_body_bytes=65536",
    "federation.egress_enabled=false",
])?;
assert_eq!(changes[0].value(), &Value::String("alpha".into()));
assert_eq!(changes[1].value(), &Value::Integer(65_536));
assert_eq!(changes[2].value(), &Value::Boolean(false));

assert!(parse_changes(["no.such.field=1"]).is_err());

§Errors

Returns a ParseChangeError for an argument without =, an unknown path, a value that does not read as the field’s type, or a non-list path given twice.