mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-08 03:36:37 +00:00
Improve gh token auto scraping (#1746)
* Log the gh-auth token retrieval failure on debug level Fixed #1733 * Make gh_token::get an async function * Improve returned err msg in gh_token::get * Update use of gh_token::get() in entry.rs * Fix typos * Fix unclosed () * Fix unclosed () * Fix gh_token.rs * Fix entry.rs * Fix fmt in entry.rs * Fix fmt in gh_token.rs * Fix fmt in gh_token.rs * Fix fmt in gh_token.rs * Fix fmt in entry.rs
This commit is contained in:
parent
22217acc51
commit
cd85622b13
2 changed files with 45 additions and 24 deletions
|
@ -1,14 +1,19 @@
|
|||
use std::{io, process};
|
||||
use std::{
|
||||
io,
|
||||
process::{Output, Stdio},
|
||||
};
|
||||
|
||||
use compact_str::CompactString;
|
||||
use tokio::process::Command;
|
||||
|
||||
pub(super) fn get() -> io::Result<CompactString> {
|
||||
let process::Output { status, stdout, .. } = process::Command::new("gh")
|
||||
pub(super) async fn get() -> io::Result<CompactString> {
|
||||
let Output { status, stdout, .. } = Command::new("gh")
|
||||
.args(["auth", "token"])
|
||||
.stdin(process::Stdio::null())
|
||||
.stdout(process::Stdio::piped())
|
||||
.stderr(process::Stdio::null())
|
||||
.output()?;
|
||||
.stdin(Stdio::null())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::null())
|
||||
.output()
|
||||
.await?;
|
||||
|
||||
if !status.success() {
|
||||
return Err(io::Error::new(
|
||||
|
@ -19,8 +24,11 @@ pub(super) fn get() -> io::Result<CompactString> {
|
|||
|
||||
// Use String here instead of CompactString here since
|
||||
// `CompactString::from_utf8` allocates if it's longer than 24B.
|
||||
let s = String::from_utf8(stdout).map_err(|_err| {
|
||||
io::Error::new(io::ErrorKind::InvalidData, "Invalid output, expected utf8")
|
||||
let s = String::from_utf8(stdout).map_err(|err| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::InvalidData,
|
||||
format!("Invalid output, expected utf8: {err}"),
|
||||
)
|
||||
})?;
|
||||
|
||||
Ok(s.trim().into())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue