Skip to main content

objectiveai_sdk/cli/command/functions/get/
mod.rs

1//! `functions get` — 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.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 into_command(&self) -> Vec<String> {
23        let mut argv = vec![
24            "functions".to_string(),
25            "get".to_string(),
26            "--path".to_string(),
27            crate::cli::command::path_ref::remote_path_to_arg_string(&self.path),
28        ];
29        self.base.push_flags(&mut argv);
30        argv
31    }
32
33    fn request_base(&self) -> &crate::cli::command::RequestBase {
34        &self.base
35    }
36
37    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
38        Some(&mut self.base)
39    }
40}
41
42/// Response for `functions get` — a resolved Function with its remote path.
43#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
44#[schemars(rename = "cli.command.functions.get.Response")]
45pub struct Response {
46    #[serde(flatten)]
47    #[schemars(schema_with = "crate::flatten_schema::<crate::RemotePath>")]
48    pub path: crate::RemotePath,
49    #[serde(flatten)]
50    #[schemars(
51        schema_with = "crate::flatten_schema::<crate::functions::FullRemoteFunction>"
52    )]
53    pub inner: crate::functions::FullRemoteFunction,
54}
55
56#[cfg(feature = "mcp")]
57impl crate::cli::command::CommandResponse for Response {
58    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
59        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
60    }
61}
62
63#[derive(clap::Args)]
64pub struct Args {
65    /// Path to the target entry.
66    #[arg(long)]
67    pub path: String,
68    #[command(flatten)]
69    pub base: crate::cli::command::RequestBaseArgs,
70}
71
72#[derive(clap::Args)]
73#[command(args_conflicts_with_subcommands = true)]
74pub struct Command {
75    #[command(flatten)]
76    pub args: Args,
77    #[command(subcommand)]
78    pub schema: Option<Schema>,
79}
80
81#[derive(clap::Subcommand)]
82pub enum Schema {
83    /// Emit the JSON Schema for this leaf's `Request` type and exit.
84    RequestSchema(request_schema::Args),
85    /// Emit the JSON Schema for this leaf's `Response` type and exit.
86    ResponseSchema(response_schema::Args),
87}
88
89impl TryFrom<Args> for Request {
90    type Error = crate::cli::command::FromArgsError;
91    fn try_from(args: Args) -> Result<Self, Self::Error> {
92        let path = args
93            .path
94            .parse::<crate::RemotePathCommitOptional>()
95            .map_err(|msg| crate::cli::command::FromArgsError::path_parse("path", msg))?;
96        Ok(Self { path_type: Path::FunctionsGet, path, base: args.base.into() })
97    }
98}
99
100#[cfg(feature = "cli-executor")]
101pub async fn execute<E: crate::cli::command::CommandExecutor>(
102    executor: &E,
103    mut request: Request,
104
105        agent_arguments: Option<&crate::cli::command::AgentArguments>,
106    ) -> Result<Response, E::Error> {
107    request.base.clear_transform();
108    executor.execute_one(request, agent_arguments).await
109}
110
111#[cfg(feature = "cli-executor")]
112pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
113    executor: &E,
114    mut request: Request,
115    transform: crate::cli::command::Transform,
116
117        agent_arguments: Option<&crate::cli::command::AgentArguments>,
118    ) -> Result<serde_json::Value, E::Error> {
119    request.base.set_transform(transform);
120    executor.execute_one(request, agent_arguments).await
121}
122
123pub mod request_schema;
124
125
126pub mod response_schema;