Skip to main content

objectiveai_sdk/cli/command/viewer/config/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.viewer.config.get.Request")]
7pub struct Request {
8    pub path_type: Path,
9    pub scope: crate::cli::command::GetScope,
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.viewer.config.get.Path")]
16pub enum Path {
17    #[serde(rename = "viewer/config/get")]
18    ViewerConfigGet,
19}
20
21impl CommandRequest for Request {
22    fn into_command(&self) -> Vec<String> {
23        let mut argv = vec!["viewer".to_string(), "config".to_string(), "get".to_string()];
24        argv.push(match self.scope {
25            crate::cli::command::GetScope::Global => "--global".to_string(),
26            crate::cli::command::GetScope::State => "--state".to_string(),
27            crate::cli::command::GetScope::Final => "--final".to_string(),
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#[derive(PartialEq, Debug, Clone, Default, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
43#[schemars(rename = "cli.command.viewer.config.get.Response")]
44pub struct Response {
45    #[serde(skip_serializing_if = "Option::is_none")]
46    #[schemars(extend("omitempty" = true))]
47    pub address: Option<String>,
48    #[serde(skip_serializing_if = "Option::is_none")]
49    #[schemars(extend("omitempty" = true))]
50    pub secret: Option<String>,
51    #[serde(skip_serializing_if = "Option::is_none")]
52    #[schemars(extend("omitempty" = true))]
53    pub signature: Option<String>,
54}
55
56#[derive(clap::Args)]
57pub struct Args {
58    /// Read the global config layer.
59    #[arg(long)]
60    pub global: bool,
61    /// Read the state config layer.
62    #[arg(long)]
63    pub state: bool,
64    /// Read the final merged config view.
65    #[arg(long)]
66    pub r#final: bool,
67    #[command(flatten)]
68    pub base: crate::cli::command::RequestBaseArgs,
69}
70
71#[derive(clap::Args)]
72#[command(args_conflicts_with_subcommands = true)]
73pub struct Command {
74    #[command(flatten)]
75    pub args: Args,
76    #[command(subcommand)]
77    pub schema: Option<Schema>,
78}
79
80#[derive(clap::Subcommand)]
81pub enum Schema {
82    /// Emit the JSON Schema for this leaf's `Request` type and exit.
83    RequestSchema(request_schema::Args),
84    /// Emit the JSON Schema for this leaf's `Response` type and exit.
85    ResponseSchema(response_schema::Args),
86}
87
88impl TryFrom<Args> for Request {
89    type Error = crate::cli::command::FromArgsError;
90    fn try_from(args: Args) -> Result<Self, Self::Error> {
91        let scope = match (args.global, args.state, args.r#final) {
92            (true, false, false) => crate::cli::command::GetScope::Global,
93            (false, true, false) => crate::cli::command::GetScope::State,
94            (false, false, true) => crate::cli::command::GetScope::Final,
95            _ => {
96                return Err(crate::cli::command::FromArgsError {
97                    field: "scope",
98                    source: crate::cli::command::FromArgsErrorSource::Plain(
99                        "exactly one of --global, --state, --final is required".to_string(),
100                    ),
101                });
102            }
103        };
104        Ok(Self { path_type: Path::ViewerConfigGet,
105            scope,
106            base: args.base.into(),
107        })
108    }
109}
110
111#[cfg(feature = "cli-executor")]
112pub async fn execute<E: crate::cli::command::CommandExecutor>(
113    executor: &E,
114    mut request: Request,
115
116        agent_arguments: Option<&crate::cli::command::AgentArguments>,
117    ) -> Result<Response, E::Error> {
118    request.base.clear_transform();
119    executor.execute_one(request, agent_arguments).await
120}
121
122#[cfg(feature = "cli-executor")]
123pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
124    executor: &E,
125    mut request: Request,
126    transform: crate::cli::command::Transform,
127
128        agent_arguments: Option<&crate::cli::command::AgentArguments>,
129    ) -> Result<serde_json::Value, E::Error> {
130    request.base.set_transform(transform);
131    executor.execute_one(request, agent_arguments).await
132}
133
134#[cfg(feature = "mcp")]
135impl crate::cli::command::CommandResponse for Response {
136    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
137        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
138    }
139}
140
141pub mod request_schema;
142
143
144pub mod response_schema;