/
basuev
/
gverse
Обзор
Документация
Войти
/
basuev
/
gverse
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/api/emails.rs
63 строки
2 KB
basuev
initial commit: gverse v0.1.0
27 май 2026, 08:52
27 май 2026, 08:52
98b24dd
Код
Авторство
О чём код?
use crate::client::Client; use crate::config::Config; use crate::error::{Error, Result}; use crate::output::{Format, print_value}; use clap::Subcommand; use reqwest::Method; use serde_json::{Map, Value}; #[derive(Subcommand, Debug)] pub enum EmailsCmd { List, Add { #[arg(required = true)] emails: Vec<String>, }, Remove { #[arg(required = true)] emails: Vec<String>, #[arg(long)] yes: bool, }, } pub async fn run(cmd: EmailsCmd, cfg: &Config, profile: Option<&str>, fmt: Format) -> Result<()> { let p = cfg.active_profile(profile)?; let client = Client::new(p)?; match cmd { EmailsCmd::List => { let v = client.get_value("/user/emails", &[]).await?; print_value(fmt, &v); Ok(()) } EmailsCmd::Add { emails } => { let mut payload = Map::new(); payload.insert( "emails".into(), Value::Array(emails.into_iter().map(Value::String).collect()), ); let v = client .send_json(Method::POST, "/user/emails", &Value::Object(payload)) .await?; print_value(fmt, &v); Ok(()) } EmailsCmd::Remove { emails, yes } => { if !yes { return Err(Error::Invalid( "refusing to remove emails without --yes".into(), )); } let mut payload = Map::new(); payload.insert( "emails".into(), Value::Array(emails.into_iter().map(Value::String).collect()), ); client .send_json(Method::DELETE, "/user/emails", &Value::Object(payload)) .await?; eprintln!("removed emails"); Ok(()) } } }