mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-15 16:53:25 +00:00
config: add convenient function that constructs ConfigLayer from TOML string
This will be used mainly in tests. The default layers might also be migrated to per-file layers constructed by ConfigLayer::parse().
This commit is contained in:
parent
d76bcd9305
commit
512d85bfad
1 changed files with 8 additions and 0 deletions
|
@ -171,6 +171,14 @@ impl ConfigLayer {
|
|||
}
|
||||
}
|
||||
|
||||
/// Parses TOML document `text` into new layer.
|
||||
pub fn parse(source: ConfigSource, text: &str) -> Result<Self, ConfigError> {
|
||||
let data = config::Config::builder()
|
||||
.add_source(config::File::from_str(text, config::FileFormat::Toml))
|
||||
.build()?;
|
||||
Ok(Self::with_data(source, data))
|
||||
}
|
||||
|
||||
fn load_from_file(source: ConfigSource, path: PathBuf) -> Result<Self, ConfigError> {
|
||||
// TODO: will be replaced with toml_edit::DocumentMut or ImDocument
|
||||
let data = config::Config::builder()
|
||||
|
|
Loading…
Reference in a new issue