/
basuev
/
gverse
Обзор
Документация
Войти
/
basuev
/
gverse
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/cli.rs
100 строк
4 KB
basuev
initial commit: gverse v0.1.0
27 май 2026, 08:52
27 май 2026, 08:52
98b24dd
Код
Авторство
О чём код?
use crate::api; use crate::config::Config; use crate::error::Result; use crate::output::Format; use clap::{CommandFactory, Parser, Subcommand}; use clap_complete::{Shell, generate}; #[derive(Parser, Debug)] #[command( name = "gverse", version, about = "Work with GitVerse from the command line.", long_about = "gverse is a command-line client for GitVerse (gitverse.ru). \ Manage repositories, pull requests, issues, releases, webhooks, \ and CI runs from your terminal. Output is human-readable by default; \ pass --json for scripting." )] pub struct Cli { #[arg(long, global = true, env = "GVERSE_PROFILE")] pub profile: Option<String>, #[arg(long, global = true)] pub json: bool, #[command(subcommand)] pub command: Command, } #[derive(Subcommand, Debug)] pub enum Command { #[command(subcommand)] Actions(api::actions::ActionsCmd), #[command(subcommand)] Auth(api::auth::AuthCmd), #[command(subcommand)] Branches(api::branches::BranchesCmd), #[command(subcommand)] Collaborators(api::collaborators::CollaboratorsCmd), #[command(subcommand)] Commits(api::commits::CommitsCmd), #[command(subcommand)] Contents(api::contents::ContentsCmd), #[command(subcommand)] Emails(api::emails::EmailsCmd), #[command(subcommand)] Issues(api::issues::IssuesCmd), #[command(subcommand)] Orgs(api::orgs::OrgsCmd), #[command(subcommand)] Pulls(api::pulls::PullsCmd), #[command(subcommand)] Refs(api::refs::RefsCmd), #[command(subcommand)] Releases(api::releases::ReleasesCmd), #[command(subcommand)] Repos(api::repos::ReposCmd), #[command(subcommand)] SmartClass(api::smartclass::SmartClassCmd), #[command(subcommand)] Stars(api::stars::StarsCmd), #[command(subcommand)] Trees(api::trees::TreesCmd), #[command(subcommand)] Users(api::users::UsersCmd), #[command(subcommand)] Webhooks(api::webhooks::WebhooksCmd), Completions { shell: Shell, }, } pub async fn run(cli: Cli) -> Result<()> { let fmt = Format::pick(cli.json); let cfg = Config::load()?; let profile = cli.profile.as_deref(); match cli.command { Command::Actions(c) => api::actions::run(c, &cfg, profile, fmt).await, Command::Auth(c) => api::auth::run(c, &cfg, profile, fmt).await, Command::Branches(c) => api::branches::run(c, &cfg, profile, fmt).await, Command::Collaborators(c) => api::collaborators::run(c, &cfg, profile, fmt).await, Command::Commits(c) => api::commits::run(c, &cfg, profile, fmt).await, Command::Contents(c) => api::contents::run(c, &cfg, profile, fmt).await, Command::Emails(c) => api::emails::run(c, &cfg, profile, fmt).await, Command::Issues(c) => api::issues::run(c, &cfg, profile, fmt).await, Command::Orgs(c) => api::orgs::run(c, &cfg, profile, fmt).await, Command::Pulls(c) => api::pulls::run(c, &cfg, profile, fmt).await, Command::Refs(c) => api::refs::run(c, &cfg, profile, fmt).await, Command::Releases(c) => api::releases::run(c, &cfg, profile, fmt).await, Command::Repos(c) => api::repos::run(c, &cfg, profile, fmt).await, Command::SmartClass(c) => api::smartclass::run(c, &cfg, profile, fmt).await, Command::Stars(c) => api::stars::run(c, &cfg, profile, fmt).await, Command::Trees(c) => api::trees::run(c, &cfg, profile, fmt).await, Command::Users(c) => api::users::run(c, &cfg, profile, fmt).await, Command::Webhooks(c) => api::webhooks::run(c, &cfg, profile, fmt).await, Command::Completions { shell } => { let mut cmd = Cli::command(); let name = cmd.get_name().to_string(); generate(shell, &mut cmd, name, &mut std::io::stdout()); Ok(()) } } }