objectiveai_sdk/cli/command/plugins/install/github/
mod.rs1use crate::cli::command::CommandRequest;
4
5#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
6#[schemars(rename = "cli.command.plugins.install.github.Request")]
7pub struct Request {
8 pub path_type: Path,
9 pub owner: String,
10 pub repository: String,
11 pub commit_sha: Option<String>,
12 pub allow_untrusted: bool,
13 pub jq: Option<String>,
14}
15
16#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
17#[schemars(rename = "cli.command.plugins.install.github.Path")]
18pub enum Path {
19 #[serde(rename = "plugins/install/github")]
20 PluginsInstallGithub,
21}
22
23impl CommandRequest for Request {
24 fn into_command(&self) -> Vec<String> {
25 let mut argv = vec![
26 "plugins".to_string(),
27 "install".to_string(),
28 "github".to_string(),
29 "--owner".to_string(),
30 self.owner.clone(),
31 "--repository".to_string(),
32 self.repository.clone(),
33 ];
34 if let Some(sha) = &self.commit_sha {
35 argv.push("--commit-sha".to_string());
36 argv.push(sha.clone());
37 }
38 if self.allow_untrusted {
39 argv.push("--allow-untrusted".to_string());
40 }
41 if let Some(jq) = &self.jq {
42 argv.push("--jq".to_string());
43 argv.push(jq.clone());
44 }
45 argv
46 }
47}
48
49#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
50#[schemars(rename = "cli.command.plugins.install.github.Response")]
51pub struct Response {
52 pub installed: bool,
53}
54
55#[derive(clap::Args)]
56pub struct Args {
57 #[arg(long)]
59 pub owner: String,
60 #[arg(long)]
62 pub repository: String,
63 #[arg(long)]
65 pub commit_sha: Option<String>,
66 #[arg(long)]
68 pub allow_untrusted: bool,
69 #[arg(long)]
71 pub jq: Option<String>,
72}
73
74#[derive(clap::Args)]
75#[command(args_conflicts_with_subcommands = true)]
76pub struct Command {
77 #[command(flatten)]
78 pub args: Args,
79 #[command(subcommand)]
80 pub schema: Option<Schema>,
81}
82
83#[derive(clap::Subcommand)]
84pub enum Schema {
85 RequestSchema(request_schema::Args),
87 ResponseSchema(response_schema::Args),
89}
90
91impl TryFrom<Args> for Request {
92 type Error = crate::cli::command::FromArgsError;
93 fn try_from(args: Args) -> Result<Self, Self::Error> {
94 Ok(Self { path_type: Path::PluginsInstallGithub,
95 owner: args.owner,
96 repository: args.repository,
97 commit_sha: args.commit_sha,
98 allow_untrusted: args.allow_untrusted,
99 jq: args.jq,
100 })
101 }
102}
103
104#[cfg(feature = "cli-executor")]
105pub async fn execute<E: crate::cli::command::CommandExecutor>(
106 executor: &E,
107 mut request: Request,
108
109 agent_arguments: Option<&crate::cli::command::AgentArguments>,
110 ) -> Result<Response, E::Error> {
111 request.jq = None;
112 executor.execute_one(request, agent_arguments).await
113}
114
115#[cfg(feature = "cli-executor")]
116pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
117 executor: &E,
118 mut request: Request,
119 jq: String,
120
121 agent_arguments: Option<&crate::cli::command::AgentArguments>,
122 ) -> Result<serde_json::Value, E::Error> {
123 request.jq = Some(jq);
124 executor.execute_one(request, agent_arguments).await
125}
126
127#[cfg(feature = "mcp")]
128impl crate::cli::command::CommandResponse for Response {
129 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
130 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
131 }
132}
133
134pub mod request_schema;
135
136
137pub mod response_schema;