mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 08:18:15 +03:00
configparser: add utility to test for HGPLAIN
Summary: Add rust utility function to test for HGPLAIN and HGPLAINEXCEPT, analagous to python's ui.plain() method. I need this so rust can expand its logic of whether to render progress bars or not. Reviewed By: quark-zju Differential Revision: D31070840 fbshipit-source-id: 0c394234b9c4337bbddaa08d7a9b1d8ed59dfec0
This commit is contained in:
parent
34562e349e
commit
67b6925885
@ -629,6 +629,25 @@ pub fn read_repo_name_from_disk(shared_dot_hg_path: &Path) -> io::Result<String>
|
||||
}
|
||||
}
|
||||
|
||||
/// Return whether plain mode is active, similar to python ui.plain().
|
||||
pub fn is_plain(feature: Option<&str>) -> bool {
|
||||
let plain = env::var(HGPLAIN);
|
||||
let plain_except = env::var(HGPLAINEXCEPT);
|
||||
|
||||
if plain.is_err() && plain_except.is_err() {
|
||||
return false;
|
||||
}
|
||||
|
||||
if let Some(feature) = feature {
|
||||
!plain_except
|
||||
.unwrap_or_default()
|
||||
.split(',')
|
||||
.any(|s| s == feature)
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@ -689,6 +708,25 @@ mod tests {
|
||||
assert_eq!(cfg.get("templatealias", "u"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_plain() {
|
||||
let _guard = ENV_LOCK.lock();
|
||||
|
||||
env::remove_var(HGPLAIN);
|
||||
env::remove_var(HGPLAINEXCEPT);
|
||||
assert!(!is_plain(None));
|
||||
|
||||
env::set_var(HGPLAIN, "1");
|
||||
assert!(is_plain(None));
|
||||
assert!(is_plain(Some("banana")));
|
||||
|
||||
env::set_var(HGPLAINEXCEPT, "dog,banana,tree");
|
||||
assert!(!is_plain(Some("banana")));
|
||||
|
||||
env::remove_var(HGPLAIN);
|
||||
assert!(!is_plain(Some("banana")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hgrcpath() {
|
||||
let _guard = crate::ENV_LOCK.lock();
|
||||
|
Loading…
Reference in New Issue
Block a user