pub struct Config { /* private fields */ }Expand description
A parsed Git configuration.
Git configuration files use an INI-like format with sections and key-value pairs. This struct provides read-only access to configuration values.
Implementations§
Source§impl Config
impl Config
Sourcepub fn from_file_with_includes<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn from_file_with_includes<P: AsRef<Path>>(path: P) -> Result<Self>
Sourcepub fn get(&self, section: &str, key: &str) -> Option<&str>
pub fn get(&self, section: &str, key: &str) -> Option<&str>
Gets a configuration value.
§Arguments
section- The section name (e.g., “user”, “core”).key- The key name (e.g., “name”, “email”).
§Returns
The value if found, or None if the key doesn’t exist.
§Example
use zerogit::config::Config;
let config = Config::from_file(".git/config").unwrap();
if let Some(name) = config.get("user", "name") {
println!("User: {}", name);
}Sourcepub fn get_subsection(
&self,
section: &str,
subsection: &str,
key: &str,
) -> Option<&str>
pub fn get_subsection( &self, section: &str, subsection: &str, key: &str, ) -> Option<&str>
Gets a configuration value from a section with a subsection.
§Arguments
section- The section name (e.g., “remote”, “branch”).subsection- The subsection name (e.g., “origin”, “main”).key- The key name (e.g., “url”, “remote”).
§Returns
The value if found, or None if the key doesn’t exist.
§Example
use zerogit::config::Config;
let config = Config::from_file(".git/config").unwrap();
if let Some(url) = config.get_subsection("remote", "origin", "url") {
println!("Origin URL: {}", url);
}Sourcepub fn get_bool(&self, section: &str, key: &str) -> Result<bool>
pub fn get_bool(&self, section: &str, key: &str) -> Result<bool>
Gets a configuration value as a boolean.
Git config supports various boolean representations:
true,yes,on,1->truefalse,no,off,0->false
§Arguments
section- The section name.key- The key name.
§Returns
Ok(bool) if the value exists and is a valid boolean,
Ok(false) if the key doesn’t exist,
Err if the value is not a valid boolean.
Sourcepub fn get_bool_subsection(
&self,
section: &str,
subsection: &str,
key: &str,
) -> Result<bool>
pub fn get_bool_subsection( &self, section: &str, subsection: &str, key: &str, ) -> Result<bool>
Gets a configuration value as a boolean from a section with a subsection.
Sourcepub fn get_int(&self, section: &str, key: &str) -> Result<i64>
pub fn get_int(&self, section: &str, key: &str) -> Result<i64>
Gets a configuration value as an integer.
Git config supports optional suffixes:
korK-> multiply by 1024morM-> multiply by 1024^2gorG-> multiply by 1024^3
§Arguments
section- The section name.key- The key name.
§Returns
Ok(i64) if the value exists and is a valid integer,
Ok(0) if the key doesn’t exist,
Err if the value is not a valid integer.
Sourcepub fn get_int_subsection(
&self,
section: &str,
subsection: &str,
key: &str,
) -> Result<i64>
pub fn get_int_subsection( &self, section: &str, subsection: &str, key: &str, ) -> Result<i64>
Gets a configuration value as an integer from a section with a subsection.
Sourcepub fn sections(&self) -> Vec<&str>
pub fn sections(&self) -> Vec<&str>
Returns all section names in the configuration.
§Returns
A vector of section names (without subsections).