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 representation for gh CLI.
- Host config representation for gh CLI.
- Mapped host configs by their hostname.
Enums§
- An error occurred in this crate.
- What protocol to use when performing git operations.
- When to interactively prompt.
Constants§
- Hostname of github.com.
Functions§
- Finds the default config directory effected by the environment.
- Determines the provided hostname is a GitHub Enterprise Server instance or not.
- Loads a file in the config directory as
T
type. - Retrieves a token from the environment variables
GH_TOKEN
orGITHUB_TOKEN
. Also tries to retrieve fromGH_ENTERPRISE_TOKEN
orGITHUB_ENTERPRISE_TOKEN
, if the enterprise flag enabled. - 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.