diff --git a/radicle-cli/examples/rad-config.md b/radicle-cli/examples/rad-config.md index e47467da..e26fd17d 100644 --- a/radicle-cli/examples/rad-config.md +++ b/radicle-cli/examples/rad-config.md @@ -68,3 +68,81 @@ z6MksmpU5b1dS7oaqF2bHXhQi1DWy2hB7Mh9CuN7y1DN6QSz@seed.radicle.xyz:8776 $ rad config get node.limits.routingMaxSize 1000 ``` + +You can set scalar values by path. + +``` +$ rad config set node.alias bob +bob +$ rad config get node.alias +bob +``` + +You can push a value to a collection by path. + +``` +$ rad config push web.pinned.repositories rad:z3TajuiHXifEDEX4qbJxe8nXr9ufi +rad:z3TajuiHXifEDEX4qbJxe8nXr9ufi +$ rad config push web.pinned.repositories rad:z3trNYnLWS11cJWC6BbxDs5niGo82 +rad:z3TajuiHXifEDEX4qbJxe8nXr9ufi +rad:z3trNYnLWS11cJWC6BbxDs5niGo82 +``` + +You can remove a value from a collection by path. + +``` +$ rad config remove web.pinned.repositories rad:z3TajuiHXifEDEX4qbJxe8nXr9ufi +rad:z3trNYnLWS11cJWC6BbxDs5niGo82 +``` + +Values that are not strictly required for a working configuration, such as +optional values or additional user-defined values, can be deleted. + +``` +$ rad config set web.name alice +alice +$ rad config unset web.name +``` + +``` (fail) +$ rad config get web.name +✗ Error: configuration error: web.name does not exist +``` + +Values along the path will be created if necessary. + +``` +$ rad config set value.a.future.update.might.add.value 5 +5 +$ rad config push value.a.future.update.might.add.collection 1 +1 +``` + +``` +$ rad config push node.array a +a +$ rad config push node.array b +a +b +``` + +Values that are required for a valid config can't be deleted. + +``` (fail) +$ rad config unset node.alias +✗ Error: configuration JSON error: missing field `alias` +``` + +Values for changes are being validated. + +``` (fail) +$ rad config set web.pinned.repositories 5 +✗ Error: configuration JSON error: invalid type: integer `5`, expected a sequence +``` + +The type of the operation is validated. + +``` (fail) +$ rad config push node.alias eve +✗ Error: the element at the path 'node.alias' is not a JSON array +``` diff --git a/radicle-cli/src/commands/config.rs b/radicle-cli/src/commands/config.rs index 568a7089..56f00c92 100644 --- a/radicle-cli/src/commands/config.rs +++ b/radicle-cli/src/commands/config.rs @@ -6,7 +6,7 @@ use std::str::FromStr; use anyhow::anyhow; use radicle::node::Alias; -use radicle::profile::Config; +use radicle::profile::{Config, ConfigError, ConfigPath, RawConfig}; use crate::terminal as term; use crate::terminal::args::{Args, Error, Help}; @@ -24,6 +24,10 @@ Usage rad config init --alias [