Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

69 linesCodeBlameRaw
1//! The commands.
2
3pub mod alias;
4pub mod api;
5pub mod auth;
6pub mod browse;
7pub mod deploy;
8pub mod issue;
9pub mod logs;
10pub mod pr;
11pub mod repo;
12pub mod run;
13pub mod secret;
14pub mod status;
15
16use clap::CommandFactory;
17
18use crate::cli::{Cli, Command};
19use crate::context::Ctx;
20use crate::error::{Error, Result};
21
22pub fn dispatch(cli: Cli) -> Result<()> {
23 match cli.command {
24 Command::Completion(args) => {
25 let mut command = Cli::command();
26 clap_complete::generate(args.shell, &mut command, "g1t", &mut std::io::stdout());
27 Ok(())
28 }
29 Command::Push(args) => {
30 let push = crate::push::Push::from_args(args).map_err(Error::usage)?;
31 push.run().map_err(Error::failed)
32 }
33 Command::Alias(command) => alias::run(command),
34 Command::Auth(command) => auth::run(Ctx::new(cli.global)?, command),
35 Command::Repo(command) => repo::run(&Ctx::new(cli.global)?, command),
36 Command::Issue(command) => issue::run(&Ctx::new(cli.global)?, command),
37 Command::Pr(command) => pr::run(&Ctx::new(cli.global)?, command),
38 Command::Run(command) => run::run(&Ctx::new(cli.global)?, command),
39 Command::Secret(command) => secret::run(&Ctx::new(cli.global)?, command),
40 Command::Deploy(command) => deploy::run(&Ctx::new(cli.global)?, command),
41 Command::Logs(args) => logs::run(&Ctx::new(cli.global)?, args),
42 Command::Status(_) => status::run(&Ctx::new(cli.global)?),
43 Command::Api(args) => api::run(&Ctx::new(cli.global)?, args),
44 Command::Browse(args) => browse::run(&Ctx::new(cli.global)?, args),
45 }
46}
47
48/// `@me` is the signed-in account.
49pub fn who(ctx: &Ctx, client: &crate::client::Client, login: &str) -> Result<String> {
50 if login == "@me" {
51 ctx.me(client)
52 } else {
53 Ok(login.trim_start_matches('@').to_owned())
54 }
55}
56
57/// The items of a list answer, which comes bare or under a key.
58pub fn items(value: serde_json::Value, key: &str) -> Vec<serde_json::Value> {
59 match value {
60 serde_json::Value::Array(list) => list,
61 mut other => match other.get_mut(key).map(serde_json::Value::take) {
62 Some(serde_json::Value::Array(list)) => list,
63 _ => match other.get_mut("items").map(serde_json::Value::take) {
64 Some(serde_json::Value::Array(list)) => list,
65 _ => Vec::new(),
66 },
67 },
68 }
69}