Skip to main content

objectiveai_sdk/cli/command/plugins/install/github/
mod.rs

1//! `plugins install github` — async handler stub.
2
3use 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    #[serde(flatten)]
14    pub base: crate::cli::command::RequestBase,
15}
16
17#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
18#[schemars(rename = "cli.command.plugins.install.github.Path")]
19pub enum Path {
20    #[serde(rename = "plugins/install/github")]
21    PluginsInstallGithub,
22}
23
24impl CommandRequest for Request {
25    fn into_command(&self) -> Vec<String> {
26        let mut argv = vec![
27            "plugins".to_string(),
28            "install".to_string(),
29            "github".to_string(),
30            "--owner".to_string(),
31            self.owner.clone(),
32            "--repository".to_string(),
33            self.repository.clone(),
34        ];
35        if let Some(sha) = &self.commit_sha {
36            argv.push("--commit-sha".to_string());
37            argv.push(sha.clone());
38        }
39        if self.allow_untrusted {
40            argv.push("--allow-untrusted".to_string());
41        }
42        self.base.push_flags(&mut argv);
43        argv
44    }
45
46    fn request_base(&self) -> &crate::cli::command::RequestBase {
47        &self.base
48    }
49
50    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
51        Some(&mut self.base)
52    }
53}
54
55#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
56#[schemars(rename = "cli.command.plugins.install.github.Response")]
57pub struct Response {
58    pub installed: bool,
59}
60
61#[derive(clap::Args)]
62pub struct Args {
63    /// GitHub repository owner.
64    #[arg(long)]
65    pub owner: String,
66    /// GitHub repository name.
67    #[arg(long)]
68    pub repository: String,
69    /// Pin install to a specific commit.
70    #[arg(long)]
71    pub commit_sha: Option<String>,
72    /// Permit installs from untrusted sources.
73    #[arg(long)]
74    pub allow_untrusted: bool,
75    #[command(flatten)]
76    pub base: crate::cli::command::RequestBaseArgs,
77}
78
79#[derive(clap::Args)]
80#[command(args_conflicts_with_subcommands = true)]
81pub struct Command {
82    #[command(flatten)]
83    pub args: Args,
84    #[command(subcommand)]
85    pub schema: Option<Schema>,
86}
87
88#[derive(clap::Subcommand)]
89pub enum Schema {
90    /// Emit the JSON Schema for this leaf's `Request` type and exit.
91    RequestSchema(request_schema::Args),
92    /// Emit the JSON Schema for this leaf's `Response` type and exit.
93    ResponseSchema(response_schema::Args),
94}
95
96impl TryFrom<Args> for Request {
97    type Error = crate::cli::command::FromArgsError;
98    fn try_from(args: Args) -> Result<Self, Self::Error> {
99        Ok(Self { path_type: Path::PluginsInstallGithub,
100            owner: args.owner,
101            repository: args.repository,
102            commit_sha: args.commit_sha,
103            allow_untrusted: args.allow_untrusted,
104            base: args.base.into(),
105        })
106    }
107}
108
109#[cfg(feature = "cli-executor")]
110pub async fn execute<E: crate::cli::command::CommandExecutor>(
111    executor: &E,
112    mut request: Request,
113
114        agent_arguments: Option<&crate::cli::command::AgentArguments>,
115    ) -> Result<Response, E::Error> {
116    request.base.clear_transform();
117    executor.execute_one(request, agent_arguments).await
118}
119
120#[cfg(feature = "cli-executor")]
121pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
122    executor: &E,
123    mut request: Request,
124    transform: crate::cli::command::Transform,
125
126        agent_arguments: Option<&crate::cli::command::AgentArguments>,
127    ) -> Result<serde_json::Value, E::Error> {
128    request.base.set_transform(transform);
129    executor.execute_one(request, agent_arguments).await
130}
131
132#[cfg(feature = "mcp")]
133impl crate::cli::command::CommandResponse for Response {
134    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
135        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
136    }
137}
138
139pub mod request_schema;
140
141
142pub mod response_schema;