use crate::cli::command::CommandRequest;
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.tools.install.github.Request")]
pub struct Request {
pub path_type: Path,
pub owner: String,
pub repository: String,
pub commit_sha: Option<String>,
pub allow_untrusted: bool,
#[serde(flatten)]
pub base: crate::cli::command::RequestBase,
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.tools.install.github.Path")]
pub enum Path {
#[serde(rename = "tools/install/github")]
ToolsInstallGithub,
}
impl CommandRequest for Request {
fn request_base(&self) -> &crate::cli::command::RequestBase {
&self.base
}
fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
Some(&mut self.base)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
#[schemars(rename = "cli.command.tools.install.github.Response")]
pub struct Response {
pub installed: bool,
}
#[derive(clap::Args)]
#[command(group(clap::ArgGroup::new("owner_required").required(true).args(["owner"])))]
#[command(group(clap::ArgGroup::new("repository_required").required(true).args(["repository"])))]
pub struct Args {
#[arg(long)]
pub owner: Option<String>,
#[arg(long)]
pub repository: Option<String>,
#[arg(long)]
pub commit_sha: Option<String>,
#[arg(long)]
pub allow_untrusted: bool,
#[command(flatten)]
pub base: crate::cli::command::RequestBaseArgs,
}
#[derive(clap::Args)]
#[command(args_conflicts_with_subcommands = true)]
pub struct Command {
#[command(flatten)]
pub args: Args,
#[command(subcommand)]
pub schema: Option<Schema>,
}
#[derive(clap::Subcommand)]
pub enum Schema {
RequestSchema(request_schema::Args),
ResponseSchema(response_schema::Args),
}
impl TryFrom<Args> for Request {
type Error = crate::cli::command::FromArgsError;
fn try_from(args: Args) -> Result<Self, Self::Error> {
Ok(Self { path_type: Path::ToolsInstallGithub,
owner: args.owner.ok_or_else(|| {
crate::cli::command::FromArgsError::path_parse(
"owner",
"--owner is required".to_string(),
)
})?,
repository: args.repository.ok_or_else(|| {
crate::cli::command::FromArgsError::path_parse(
"repository",
"--repository is required".to_string(),
)
})?,
commit_sha: args.commit_sha,
allow_untrusted: args.allow_untrusted,
base: args.base.into(),
})
}
}
#[cfg(feature = "cli-executor")]
pub async fn execute<E: crate::cli::command::CommandExecutor>(
executor: &E,
mut request: Request,
agent_arguments: Option<&crate::cli::command::AgentArguments>,
) -> Result<Response, E::Error> {
request.base.clear_transform();
executor.execute_one(request, agent_arguments).await
}
#[cfg(feature = "cli-executor")]
pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
executor: &E,
mut request: Request,
transform: crate::cli::command::Transform,
agent_arguments: Option<&crate::cli::command::AgentArguments>,
) -> Result<serde_json::Value, E::Error> {
request.base.set_transform(transform);
executor.execute_one(request, agent_arguments).await
}
#[cfg(feature = "mcp")]
impl crate::cli::command::CommandResponse for Response {
fn into_mcp(self) -> crate::cli::command::McpResponseItem {
crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
}
}
pub mod request_schema;
pub mod response_schema;