Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
Signed-off-by: Jess Frazelle <[email protected]>
  • Loading branch information
jessfraz committed Jun 5, 2024
1 parent 13fa2f9 commit b4346a6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,19 @@ pub fn validate_value(key: &str, value: &str) -> Result<()> {
// new_from_string initializes a Config from a toml string.
#[cfg(test)]
fn new_from_string(s: &str) -> Result<impl Config> {
let root = s.parse::<toml_edit::Document>()?;
let root = s.parse::<toml_edit::DocumentMut>()?;
Ok(new_config(root))
}

pub fn new_config(t: toml_edit::Document) -> impl Config {
pub fn new_config(t: toml_edit::DocumentMut) -> impl Config {
crate::config_from_file::FileConfig {
map: crate::config_map::ConfigMap {
root: t.as_table().clone(),
},
}
}

pub fn new_blank_root() -> Result<toml_edit::Document> {
pub fn new_blank_root() -> Result<toml_edit::DocumentMut> {
let mut s = String::new();
for option in config_options() {
if !option.comment.is_empty() {
Expand All @@ -161,7 +161,7 @@ pub fn new_blank_root() -> Result<toml_edit::Document> {
writeln!(s, "{} = \"{}\"\n", option.key, option.default_value)?;
}

Ok(s.parse::<toml_edit::Document>()?)
Ok(s.parse::<toml_edit::DocumentMut>()?)
}

#[cfg(test)]
Expand Down
4 changes: 2 additions & 2 deletions src/config_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ pub fn parse_default_config() -> Result<impl crate::config::Config> {
} else {
// Get the default config from the file.
let contents = read_config_file(&config_file_path)?;
contents.parse::<toml_edit::Document>()?
contents.parse::<toml_edit::DocumentMut>()?
};

// Parse the hosts file.
let hosts_file_path = hosts_file()?;
let path = Path::new(&hosts_file_path);
if path.exists() {
let contents = read_config_file(&hosts_file_path)?;
let doc = contents.parse::<toml_edit::Document>()?;
let doc = contents.parse::<toml_edit::DocumentMut>()?;
let hosts = doc.as_table().clone();
root.insert("hosts", toml_edit::Item::Table(hosts));
}
Expand Down
4 changes: 2 additions & 2 deletions src/config_from_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,13 @@ impl crate::config::Config for FileConfig {

map.remove_entry("hosts")?;

let doc: toml_edit::Document = map.root.into();
let doc: toml_edit::DocumentMut = map.root.into();

Ok(doc.to_string().trim().to_string())
}

fn hosts_to_string(&self) -> Result<String> {
let doc: toml_edit::Document = self.get_hosts_table()?.into();
let doc: toml_edit::DocumentMut = self.get_hosts_table()?.into();

Ok(doc.to_string().trim().to_string())
}
Expand Down

0 comments on commit b4346a6

Please sign in to comment.