/
basuev
/
gverse
Обзор
Документация
Войти
/
basuev
/
gverse
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/api/mod.rs
81 строка
2 KB
basuev
initial commit: gverse v0.1.0
27 май 2026, 08:52
27 май 2026, 08:52
98b24dd
Код
Авторство
О чём код?
pub mod actions; pub mod auth; pub mod branches; pub mod collaborators; pub mod commits; pub mod contents; pub mod emails; pub mod issues; pub mod orgs; pub mod pulls; pub mod refs; pub mod releases; pub mod repos; pub mod smartclass; pub mod stars; pub mod trees; pub mod users; pub mod webhooks; use crate::error::{Error, Result}; use crate::client::Client; use std::path::Path; pub async fn download_to_output( client: &Client, url: &str, output: Option<&Path>, tty_refusal_label: Option<&str>, ) -> Result<()> { use std::io::IsTerminal; use tokio::fs; if let Some(out) = output { let mut f = fs::File::create(out).await?; let n = client.download_to(url, &mut f).await?; eprintln!("wrote {n} bytes to {}", out.display()); } else { if let Some(label) = tty_refusal_label && std::io::stdout().is_terminal() { return Err(Error::Invalid(format!( "refusing to write {label} to a terminal; pass --output FILE or redirect stdout" ))); } let mut stdout = tokio::io::stdout(); client.download_to(url, &mut stdout).await?; } Ok(()) } async fn read_stdin_to_string() -> Result<String> { use tokio::io::AsyncReadExt; let mut buf = String::new(); tokio::io::stdin().read_to_string(&mut buf).await?; Ok(buf) } pub async fn read_stdin_to_bytes() -> Result<Vec<u8>> { use tokio::io::AsyncReadExt; let mut buf = Vec::new(); tokio::io::stdin().read_to_end(&mut buf).await?; Ok(buf) } pub async fn resolve_string(s: String) -> Result<String> { if s == "-" { read_stdin_to_string().await } else { Ok(s) } } pub fn split_repo(s: &str) -> Result<(&str, &str)> { let (owner, name) = s .split_once('/') .ok_or_else(|| Error::Invalid(format!("expected `owner/repo`, got `{s}`")))?; if owner.is_empty() || name.is_empty() || name.contains('/') { return Err(Error::Invalid(format!("expected `owner/repo`, got `{s}`"))); } Ok((owner, name)) }