objectiveai_sdk/cli/command/functions/get/
mod.rs1use crate::cli::command::CommandRequest;
4
5#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
6#[schemars(rename = "cli.command.functions.get.Request")]
7pub struct Request {
8 pub path_type: Path,
9 pub path: crate::RemotePathCommitOptional,
10 #[serde(flatten)]
11 pub base: crate::cli::command::RequestBase,
12}
13
14#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
15#[schemars(rename = "cli.command.functions.get.Path")]
16pub enum Path {
17 #[serde(rename = "functions/get")]
18 FunctionsGet,
19}
20
21impl CommandRequest for Request {
22 fn request_base(&self) -> &crate::cli::command::RequestBase {
23 &self.base
24 }
25
26 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
27 Some(&mut self.base)
28 }
29}
30
31#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
33#[schemars(rename = "cli.command.functions.get.Response")]
34pub struct Response {
35 #[serde(flatten)]
36 #[schemars(schema_with = "crate::flatten_schema::<crate::RemotePath>")]
37 pub path: crate::RemotePath,
38 #[serde(flatten)]
39 #[schemars(
40 schema_with = "crate::flatten_schema::<crate::functions::FullRemoteFunction>"
41 )]
42 pub inner: crate::functions::FullRemoteFunction,
43}
44
45#[cfg(feature = "mcp")]
46impl crate::cli::command::CommandResponse for Response {
47 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
48 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
49 }
50}
51
52#[derive(clap::Args)]
53#[command(group(clap::ArgGroup::new("path_required").required(true).args(["path"])))]
54pub struct Args {
55 #[arg(long)]
57 pub path: Option<String>,
58 #[command(flatten)]
59 pub base: crate::cli::command::RequestBaseArgs,
60}
61
62#[derive(clap::Args)]
63#[command(args_conflicts_with_subcommands = true)]
64pub struct Command {
65 #[command(flatten)]
66 pub args: Args,
67 #[command(subcommand)]
68 pub schema: Option<Schema>,
69}
70
71#[derive(clap::Subcommand)]
72pub enum Schema {
73 RequestSchema(request_schema::Args),
75 ResponseSchema(response_schema::Args),
77}
78
79impl TryFrom<Args> for Request {
80 type Error = crate::cli::command::FromArgsError;
81 fn try_from(args: Args) -> Result<Self, Self::Error> {
82 let path = args
83 .path
84 .ok_or_else(|| {
85 crate::cli::command::FromArgsError::path_parse(
86 "path",
87 "--path is required".to_string(),
88 )
89 })?
90 .parse::<crate::RemotePathCommitOptional>()
91 .map_err(|msg| crate::cli::command::FromArgsError::path_parse("path", msg))?;
92 Ok(Self { path_type: Path::FunctionsGet, path, base: args.base.into() })
93 }
94}
95
96#[cfg(feature = "cli-executor")]
97pub async fn execute<E: crate::cli::command::CommandExecutor>(
98 executor: &E,
99 mut request: Request,
100
101 agent_arguments: Option<&crate::cli::command::AgentArguments>,
102 ) -> Result<Response, E::Error> {
103 request.base.clear_transform();
104 executor.execute_one(request, agent_arguments).await
105}
106
107#[cfg(feature = "cli-executor")]
108pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
109 executor: &E,
110 mut request: Request,
111 transform: crate::cli::command::Transform,
112
113 agent_arguments: Option<&crate::cli::command::AgentArguments>,
114 ) -> Result<serde_json::Value, E::Error> {
115 request.base.set_transform(transform);
116 executor.execute_one(request, agent_arguments).await
117}
118
119pub mod request_schema;
120
121
122pub mod response_schema;