diff options
author | Teddy Wing | 2020-08-02 18:49:36 +0200 |
---|---|---|
committer | Teddy Wing | 2020-08-02 18:49:51 +0200 |
commit | 8e5ac6f2d4e52eea95e5a6fc2905ce511ac4956e (patch) | |
tree | f5e56fbf1fc673c8a75f160c297fa79d0937e0d4 /src/config.rs | |
parent | 646ed6c2027864b6373453c2f529796f01b3e715 (diff) | |
download | git-suggestion-8e5ac6f2d4e52eea95e5a6fc2905ce511ac4956e.tar.bz2 |
Add documentation comments
Light documentation for our various functions and types.
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs index e605439..39a8158 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,8 +8,10 @@ use thiserror::Error; use crate::owner_repo::{self, OwnerRepo}; +/// Program-specific prefix for Git config values. const GIT_CONFIG_PREFIX: &'static str = "githubSuggestion."; +/// Configuration errors. #[derive(Debug, Error)] pub enum Error { #[error("Unable to parse arguments: {0}")] @@ -28,6 +30,7 @@ pub enum Error { Git(#[from] git2::Error), } +/// Configuration extracted from config files and command line arguments. pub struct Config { pub github_token: String, pub o_r: Result<OwnerRepo, owner_repo::Error>, @@ -35,6 +38,8 @@ pub struct Config { } impl Config { + /// Set up command line arguments. Extract configuration values from command + /// line arguments, Git config, and environment variables. pub fn get(args: &[String], usage_brief: &str) -> Result<Self, Error> { let mut opts = Options::new(); @@ -79,6 +84,11 @@ impl Config { }) } + /// Get a GitHub token, checking the following places in order: + /// + /// 1. Command line argument + /// 2. Git config + /// 3. Environment variable fn github_token( opt_matches: &getopts::Matches, git_config: &git2::Config, @@ -101,6 +111,12 @@ impl Config { } } + /// Get the Git remote name from the following places in order: + /// + /// 1. Command line argument + /// 2. Git config + /// + /// If the value wasn't set, return `Ok(None)`. fn remote( opt_matches: &getopts::Matches, git_config: &git2::Config, @@ -115,10 +131,12 @@ impl Config { } } +/// Print command line usage information to standard output. fn print_usage(opts: &Options, brief: &str) { print!("{}", opts.usage(brief)); } +/// Build a Git config key using the program-specific prefix and a subkey. fn git_config_key(key: &str) -> String { format!("{}.{}", GIT_CONFIG_PREFIX, key) } |