Skip to main content

objectiveai_sdk/cli/command/config/viewer/get/
mod.rs

1//! `config viewer 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.config.viewer.get.Request")]
7pub struct Request {
8    pub path_type: Path,
9    pub filter: Option<String>,
10    pub jq: Option<String>,
11}
12
13#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
14#[schemars(rename = "cli.command.config.viewer.get.Path")]
15pub enum Path {
16    #[serde(rename = "config/viewer/get")]
17    ConfigViewerGet,
18}
19
20impl CommandRequest for Request {
21    fn into_command(&self) -> Vec<String> {
22        let mut argv = vec!["config".to_string(), "viewer".to_string(), "get".to_string()];
23        if let Some(filter) = &self.filter {
24            argv.push(filter.clone());
25        }
26        if let Some(jq) = &self.jq {
27            argv.push("--jq".to_string());
28            argv.push(jq.clone());
29        }
30        argv
31    }
32}
33
34#[derive(PartialEq, Debug, Clone, Default, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
35#[schemars(rename = "cli.command.config.viewer.get.Response")]
36pub struct Response {
37    #[serde(skip_serializing_if = "Option::is_none")]
38    #[schemars(extend("omitempty" = true))]
39    pub address: Option<String>,
40    #[serde(skip_serializing_if = "Option::is_none")]
41    #[schemars(extend("omitempty" = true))]
42    pub port: Option<u16>,
43    #[serde(skip_serializing_if = "Option::is_none")]
44    #[schemars(extend("omitempty" = true))]
45    pub secret: Option<String>,
46    #[serde(skip_serializing_if = "Option::is_none")]
47    #[schemars(extend("omitempty" = true))]
48    pub signature: Option<String>,
49}
50
51#[derive(clap::Args)]
52pub struct Args {
53    /// Optional path filter into the config tree.
54    pub filter: Option<String>,
55    /// jq filter applied to the JSON output.
56    #[arg(long)]
57    pub jq: Option<String>,
58}
59
60#[derive(clap::Args)]
61#[command(args_conflicts_with_subcommands = true)]
62pub struct Command {
63    #[command(flatten)]
64    pub args: Args,
65    #[command(subcommand)]
66    pub schema: Option<Schema>,
67}
68
69#[derive(clap::Subcommand)]
70pub enum Schema {
71    /// Emit the JSON Schema for this leaf's `Request` type and exit.
72    RequestSchema(request_schema::Args),
73    /// Emit the JSON Schema for this leaf's `Response` type and exit.
74    ResponseSchema(response_schema::Args),
75}
76
77impl TryFrom<Args> for Request {
78    type Error = crate::cli::command::FromArgsError;
79    fn try_from(args: Args) -> Result<Self, Self::Error> {
80        Ok(Self { path_type: Path::ConfigViewerGet,
81            filter: args.filter,
82            jq: args.jq,
83        })
84    }
85}
86
87#[cfg(feature = "cli-executor")]
88pub async fn execute<E: crate::cli::command::CommandExecutor>(
89    executor: &E,
90    mut request: Request,
91
92        agent_arguments: Option<&crate::cli::command::AgentArguments>,
93    ) -> Result<Response, E::Error> {
94    request.jq = None;
95    executor.execute_one(request, agent_arguments).await
96}
97
98#[cfg(feature = "cli-executor")]
99pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
100    executor: &E,
101    mut request: Request,
102    jq: String,
103
104        agent_arguments: Option<&crate::cli::command::AgentArguments>,
105    ) -> Result<serde_json::Value, E::Error> {
106    request.jq = Some(jq);
107    executor.execute_one(request, agent_arguments).await
108}
109
110#[cfg(feature = "mcp")]
111impl crate::cli::command::CommandResponse for Response {
112    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
113        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
114    }
115}
116
117pub mod request_schema;
118
119
120pub mod response_schema;