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
orGITHUB_TOKEN
. Also tries to retrieve fromGH_ENTERPRISE_TOKEN
orGITHUB_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.