Crate gh_config

Source
Expand description

§gh-config

Loads config and hosts for gh CLI.

§Getting started

[dependencies]
gh-config = "0.3"

§Usage

use std::error::Error;
use gh_config::*;

fn main() -> Result<(), Box<dyn Error>> {
    let config = Config::load()?;
    let hosts = Hosts::load()?;
     
    match hosts.get(GITHUB_COM) {
        Some(host) => println!("Token for github.com: {}", hosts.retrieve_token(GITHUB_COM)?.unwrap()),
        _ => eprintln!("Token not found."),
    }

    Ok(())
}

Structs§

Config
Config representation for gh CLI.
Host
Host config representation for gh CLI.
Hosts
Mapped host configs by their hostname.

Enums§

Error
An error occurred in this crate.
GitProtocol
What protocol to use when performing git operations.
Prompt
When to interactively prompt.

Constants§

GHE_COM
GITHUB_COM
Hostname of github.com.
LOCALHOST

Functions§

find_config_directory
Finds the default config directory effected by the environment.
is_enterprise
Determines the provided hostname is a GitHub Enterprise Server instance or not.
load
Loads a file in the config directory as T type.
retrieve_token_from_env
Retrieves a token from the environment variables GH_TOKEN or GITHUB_TOKEN. Also tries to retrieve from GH_ENTERPRISE_TOKEN or GITHUB_ENTERPRISE_TOKEN, if the enterprise flag enabled.
retrieve_token_secure
Retrieves a token from the secure storage. User interaction may be required to unlock the keychain, depending on the OS. If any token found for the hostname, returns None.