2 releases
Uses old Rust 2015
0.1.1 | Jun 18, 2019 |
---|---|
0.1.0 | Jan 1, 2018 |
#147 in #monitor
31KB
554 lines
repomon
lib.rs
:
Configuration management for repomon.
Examples
Read from TOML string
#
#
#
#
let test_toml = r#"basedir = "/home/jozias/projects"
[[repos.ar2.remotes]]
name = "origin"
url = "jozias@jasonozias.com:repos/ar2.git"
[[repos.ar2.branch]]
name = "master"
interval = "1m"
remotes = ["origin"]
[[repos.repomon.remotes]]
name = "origin"
url = "jozias@jasonozias.com:repos/repomon.git"
[[repos.repomon.remotes]]
name = "gh"
url = "git@github.com:rustyhorde/repomon.git"
[[repos.repomon.branch]]
name = "master"
interval = "1m"
remotes = ["origin", "gh"]
[[repos.repomon.branch]]
name = "feature/testing"
interval = "1m"
remotes = ["origin", "gh"]
"#;
// Serialize the TOML above into a `Repomon` struct.
let mut reader = Cursor::new(test_toml);
let repomon = read_toml(&mut reader)?;
// Check the `Repomon` struct.
let repos = repomon.repos();
assert_eq!(repos.keys().len(), 2);
assert!(repos.contains_key("repomon"));
assert!(repos.contains_key("ar2"));
Write to TOML string
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
let mut repomon: Repomon = Default::default();
repomon.set_basedir("/home/jozias/projects".to_string());
repomon.set_repos(repo_map);
// Write the TOML to the given buf.
let mut buf = [0; 5000];
// Wrapped to drop mutable borrow.
{
let mut writer = Cursor::new(&mut buf[..]);
write_toml(&repomon, &mut writer)?;
}
// Check that the result is the same as the TOML above.
let filtered = buf.iter().filter(|x| **x > 0).cloned().collect::<Vec<u8>>();
assert_eq!(
TEST_TOML,
String::from_utf8(filtered).expect("Invalid UTF-8 in result")
);
Dependencies
~8–14MB
~211K SLoC