objectiveai_sdk/cli/command/update/
mod.rs1use crate::cli::command::CommandRequest;
4
5#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
6#[schemars(rename = "cli.command.update.Request")]
7pub struct Request {
8 pub path_type: Path,
9 pub jq: Option<String>,
10}
11
12#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
13#[schemars(rename = "cli.command.update.Path")]
14pub enum Path {
15 #[serde(rename = "update")]
16 Update,
17}
18impl CommandRequest for Request {
19 fn into_command(&self) -> Vec<String> {
20 let mut argv = vec!["update".to_string()];
21 if let Some(jq) = &self.jq {
22 argv.push("--jq".to_string());
23 argv.push(jq.clone());
24 }
25 argv
26 }
27}
28
29#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
33#[serde(tag = "type", rename_all = "snake_case")]
34#[schemars(rename = "cli.command.update.ResponseItem")]
35pub enum ResponseItem {
36 #[schemars(title = "Checking")]
37 Checking {
38 asset_name: String,
39 current_version: String,
40 },
41 #[schemars(title = "Found")]
42 Found {
43 current_version: String,
44 remote_version: String,
45 asset_name: String,
46 url: String,
47 },
48 #[schemars(title = "Installed")]
49 Installed {
50 current_version: String,
51 remote_version: String,
52 },
53 #[schemars(title = "Skipped")]
54 Skipped {
55 reason: ResponseSkipReason,
56 },
57 #[schemars(title = "UpToDate")]
58 UpToDate {
59 current_version: String,
60 remote_version: String,
61 },
62}
63
64#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
68#[schemars(rename = "cli.command.update.Response")]
69pub struct Response {
70 pub items: Vec<ResponseItem>,
71}
72
73#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
74#[serde(rename_all = "snake_case")]
75#[schemars(rename = "cli.command.update.ResponseSkipReason")]
76pub enum ResponseSkipReason {
77 DevTree,
78 UnsupportedPlatform,
79 IncompleteRelease,
80}
81
82#[derive(clap::Args)]
83pub struct Args {
84 #[arg(long)]
86 pub jq: Option<String>,
87}
88
89#[derive(clap::Args)]
90#[command(args_conflicts_with_subcommands = true)]
91pub struct Command {
92 #[command(flatten)]
93 pub args: Args,
94 #[command(subcommand)]
95 pub schema: Option<Schema>,
96}
97
98#[derive(clap::Subcommand)]
99pub enum Schema {
100 RequestSchema(request_schema::Args),
102 ResponseSchema(response_schema::Args),
104}
105
106impl TryFrom<Args> for Request {
107 type Error = crate::cli::command::FromArgsError;
108 fn try_from(args: Args) -> Result<Self, Self::Error> {
109 Ok(Self { path_type: Path::Update, jq: args.jq })
110 }
111}
112
113#[cfg(feature = "cli-executor")]
114pub async fn execute<E: crate::cli::command::CommandExecutor>(
115 executor: &E,
116 mut request: Request,
117
118 agent_arguments: Option<&crate::cli::command::AgentArguments>,
119 ) -> Result<E::Stream<ResponseItem>, E::Error> {
120 request.jq = None;
121 executor.execute(request, agent_arguments).await
122}
123
124#[cfg(feature = "cli-executor")]
125pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
126 executor: &E,
127 mut request: Request,
128 jq: String,
129
130 agent_arguments: Option<&crate::cli::command::AgentArguments>,
131 ) -> Result<E::Stream<serde_json::Value>, E::Error> {
132 request.jq = Some(jq);
133 executor.execute(request, agent_arguments).await
134}
135
136#[cfg(feature = "mcp")]
137impl crate::cli::command::CommandResponse for ResponseItem {
138 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
139 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
140 }
141}
142
143#[cfg(feature = "mcp")]
144impl crate::cli::command::CommandResponse for Response {
145 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
146 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
147 }
148}
149
150pub mod request_schema;
151
152pub mod response_schema;