Skip to main content

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

1//! `functions get` — async handler stub.
2
3use crate::cli::command::{CommandRequest, RemotePathCommitOptionalOrFavorite};
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: RemotePathCommitOptionalOrFavorite,
10    pub jq: Option<String>,
11}
12
13#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
14#[schemars(rename = "cli.command.functions.get.Path")]
15pub enum Path {
16    #[serde(rename = "functions/get")]
17    FunctionsGet,
18}
19
20impl CommandRequest for Request {
21    fn into_command(&self) -> Vec<String> {
22        let mut argv = vec![
23            "functions".to_string(),
24            "get".to_string(),
25            "--path".to_string(),
26            self.path.into_arg_string(),
27        ];
28        if let Some(jq) = &self.jq {
29            argv.push("--jq".to_string());
30            argv.push(jq.clone());
31        }
32        argv
33    }
34}
35
36pub type Response = crate::functions::response::GetFunctionResponse;
37
38#[derive(clap::Args)]
39pub struct Args {
40    /// Path to the target entry.
41    #[arg(long)]
42    pub path: String,
43    /// jq filter applied to the JSON output.
44    #[arg(long)]
45    pub jq: Option<String>,
46}
47
48#[derive(clap::Args)]
49#[command(args_conflicts_with_subcommands = true)]
50pub struct Command {
51    #[command(flatten)]
52    pub args: Args,
53    #[command(subcommand)]
54    pub schema: Option<Schema>,
55}
56
57#[derive(clap::Subcommand)]
58pub enum Schema {
59    /// Emit the JSON Schema for this leaf's `Request` type and exit.
60    RequestSchema(request_schema::Args),
61    /// Emit the JSON Schema for this leaf's `Response` type and exit.
62    ResponseSchema(response_schema::Args),
63}
64
65impl TryFrom<Args> for Request {
66    type Error = crate::cli::command::FromArgsError;
67    fn try_from(args: Args) -> Result<Self, Self::Error> {
68        let path = args
69            .path
70            .parse::<RemotePathCommitOptionalOrFavorite>()
71            .map_err(|msg| crate::cli::command::FromArgsError::path_parse("path", msg))?;
72        Ok(Self { path_type: Path::FunctionsGet, path, jq: args.jq })
73    }
74}
75
76#[cfg(feature = "cli-executor")]
77pub async fn execute<E: crate::cli::command::CommandExecutor>(
78    executor: &E,
79    mut request: Request,
80
81        agent_arguments: Option<&crate::cli::command::AgentArguments>,
82    ) -> Result<Response, E::Error> {
83    request.jq = None;
84    executor.execute_one(request, agent_arguments).await
85}
86
87#[cfg(feature = "cli-executor")]
88pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
89    executor: &E,
90    mut request: Request,
91    jq: String,
92
93        agent_arguments: Option<&crate::cli::command::AgentArguments>,
94    ) -> Result<serde_json::Value, E::Error> {
95    request.jq = Some(jq);
96    executor.execute_one(request, agent_arguments).await
97}
98
99pub mod request_schema;
100
101
102pub mod response_schema;