pub struct AgentCli { /* private fields */ }Expand description
Agent-native CLI runtime.
Implementations§
Source§impl AgentCli
impl AgentCli
Sourcepub fn new(name: impl Into<String>, description: impl Into<String>) -> Self
pub fn new(name: impl Into<String>, description: impl Into<String>) -> Self
Examples found in repository?
examples/ops.rs (line 8)
7fn main() {
8 let cli = AgentCli::new("ops", "Agent-native operations CLI")
9 .version(env!("CARGO_PKG_VERSION"))
10 .root_field("health", json!({ "server": "ok", "worker": "ok" }))
11 .command(
12 Command::new("status", "Show system health")
13 .usage("ops status")
14 .handler(|_req, _ctx| {
15 Ok(CommandOutput::new(json!({
16 "healthy": true,
17 "queue_depth": 0
18 }))
19 .next_action(NextAction::new("ops status", "Re-check status"))
20 .next_action(
21 NextAction::new("ops logs <source> [--lines <lines>]", "Inspect logs")
22 .with_param(
23 "source",
24 ActionParam::new()
25 .enum_values(["worker", "errors", "server"])
26 .default("worker"),
27 )
28 .with_param(
29 "lines",
30 ActionParam::new()
31 .description("Number of lines to show")
32 .default(20),
33 ),
34 ))
35 }),
36 )
37 .command(
38 Command::new("logs", "View logs with context-safe truncation")
39 .usage("ops logs <source> [--lines <lines>] [--follow]")
40 .handler(|req, _ctx| {
41 let source = req.arg(0).unwrap_or("worker");
42 let lines = req
43 .flag("lines")
44 .and_then(|value| value.parse::<usize>().ok())
45 .unwrap_or(20);
46
47 let fake_logs = (0..120)
48 .map(|idx| format!("[{source}] line-{idx}"))
49 .collect::<Vec<_>>();
50 let payload =
51 truncate_lines_with_file(fake_logs, lines, "ops-logs").map_err(|_| {
52 CommandError::new(
53 "failed to write full log output",
54 "LOG_WRITE_FAILED",
55 "Check disk permissions and retry.",
56 )
57 })?;
58
59 Ok(
60 CommandOutput::new(json!(payload)).next_action(NextAction::new(
61 "ops logs <source> [--lines <lines>] [--follow]",
62 "Adjust line count or follow logs",
63 )),
64 )
65 }),
66 );
67
68 let run = cli.run_env();
69 println!("{}", run.to_json());
70 std::process::exit(run.exit_code());
71}Sourcepub fn version(self, version: impl Into<String>) -> Self
pub fn version(self, version: impl Into<String>) -> Self
Examples found in repository?
examples/ops.rs (line 9)
7fn main() {
8 let cli = AgentCli::new("ops", "Agent-native operations CLI")
9 .version(env!("CARGO_PKG_VERSION"))
10 .root_field("health", json!({ "server": "ok", "worker": "ok" }))
11 .command(
12 Command::new("status", "Show system health")
13 .usage("ops status")
14 .handler(|_req, _ctx| {
15 Ok(CommandOutput::new(json!({
16 "healthy": true,
17 "queue_depth": 0
18 }))
19 .next_action(NextAction::new("ops status", "Re-check status"))
20 .next_action(
21 NextAction::new("ops logs <source> [--lines <lines>]", "Inspect logs")
22 .with_param(
23 "source",
24 ActionParam::new()
25 .enum_values(["worker", "errors", "server"])
26 .default("worker"),
27 )
28 .with_param(
29 "lines",
30 ActionParam::new()
31 .description("Number of lines to show")
32 .default(20),
33 ),
34 ))
35 }),
36 )
37 .command(
38 Command::new("logs", "View logs with context-safe truncation")
39 .usage("ops logs <source> [--lines <lines>] [--follow]")
40 .handler(|req, _ctx| {
41 let source = req.arg(0).unwrap_or("worker");
42 let lines = req
43 .flag("lines")
44 .and_then(|value| value.parse::<usize>().ok())
45 .unwrap_or(20);
46
47 let fake_logs = (0..120)
48 .map(|idx| format!("[{source}] line-{idx}"))
49 .collect::<Vec<_>>();
50 let payload =
51 truncate_lines_with_file(fake_logs, lines, "ops-logs").map_err(|_| {
52 CommandError::new(
53 "failed to write full log output",
54 "LOG_WRITE_FAILED",
55 "Check disk permissions and retry.",
56 )
57 })?;
58
59 Ok(
60 CommandOutput::new(json!(payload)).next_action(NextAction::new(
61 "ops logs <source> [--lines <lines>] [--follow]",
62 "Adjust line count or follow logs",
63 )),
64 )
65 }),
66 );
67
68 let run = cli.run_env();
69 println!("{}", run.to_json());
70 std::process::exit(run.exit_code());
71}Sourcepub fn command(self, command: Command) -> Self
pub fn command(self, command: Command) -> Self
Examples found in repository?
examples/ops.rs (lines 11-36)
7fn main() {
8 let cli = AgentCli::new("ops", "Agent-native operations CLI")
9 .version(env!("CARGO_PKG_VERSION"))
10 .root_field("health", json!({ "server": "ok", "worker": "ok" }))
11 .command(
12 Command::new("status", "Show system health")
13 .usage("ops status")
14 .handler(|_req, _ctx| {
15 Ok(CommandOutput::new(json!({
16 "healthy": true,
17 "queue_depth": 0
18 }))
19 .next_action(NextAction::new("ops status", "Re-check status"))
20 .next_action(
21 NextAction::new("ops logs <source> [--lines <lines>]", "Inspect logs")
22 .with_param(
23 "source",
24 ActionParam::new()
25 .enum_values(["worker", "errors", "server"])
26 .default("worker"),
27 )
28 .with_param(
29 "lines",
30 ActionParam::new()
31 .description("Number of lines to show")
32 .default(20),
33 ),
34 ))
35 }),
36 )
37 .command(
38 Command::new("logs", "View logs with context-safe truncation")
39 .usage("ops logs <source> [--lines <lines>] [--follow]")
40 .handler(|req, _ctx| {
41 let source = req.arg(0).unwrap_or("worker");
42 let lines = req
43 .flag("lines")
44 .and_then(|value| value.parse::<usize>().ok())
45 .unwrap_or(20);
46
47 let fake_logs = (0..120)
48 .map(|idx| format!("[{source}] line-{idx}"))
49 .collect::<Vec<_>>();
50 let payload =
51 truncate_lines_with_file(fake_logs, lines, "ops-logs").map_err(|_| {
52 CommandError::new(
53 "failed to write full log output",
54 "LOG_WRITE_FAILED",
55 "Check disk permissions and retry.",
56 )
57 })?;
58
59 Ok(
60 CommandOutput::new(json!(payload)).next_action(NextAction::new(
61 "ops logs <source> [--lines <lines>] [--follow]",
62 "Adjust line count or follow logs",
63 )),
64 )
65 }),
66 );
67
68 let run = cli.run_env();
69 println!("{}", run.to_json());
70 std::process::exit(run.exit_code());
71}Sourcepub fn root_field(self, key: impl Into<String>, value: impl Into<Value>) -> Self
pub fn root_field(self, key: impl Into<String>, value: impl Into<Value>) -> Self
Examples found in repository?
examples/ops.rs (line 10)
7fn main() {
8 let cli = AgentCli::new("ops", "Agent-native operations CLI")
9 .version(env!("CARGO_PKG_VERSION"))
10 .root_field("health", json!({ "server": "ok", "worker": "ok" }))
11 .command(
12 Command::new("status", "Show system health")
13 .usage("ops status")
14 .handler(|_req, _ctx| {
15 Ok(CommandOutput::new(json!({
16 "healthy": true,
17 "queue_depth": 0
18 }))
19 .next_action(NextAction::new("ops status", "Re-check status"))
20 .next_action(
21 NextAction::new("ops logs <source> [--lines <lines>]", "Inspect logs")
22 .with_param(
23 "source",
24 ActionParam::new()
25 .enum_values(["worker", "errors", "server"])
26 .default("worker"),
27 )
28 .with_param(
29 "lines",
30 ActionParam::new()
31 .description("Number of lines to show")
32 .default(20),
33 ),
34 ))
35 }),
36 )
37 .command(
38 Command::new("logs", "View logs with context-safe truncation")
39 .usage("ops logs <source> [--lines <lines>] [--follow]")
40 .handler(|req, _ctx| {
41 let source = req.arg(0).unwrap_or("worker");
42 let lines = req
43 .flag("lines")
44 .and_then(|value| value.parse::<usize>().ok())
45 .unwrap_or(20);
46
47 let fake_logs = (0..120)
48 .map(|idx| format!("[{source}] line-{idx}"))
49 .collect::<Vec<_>>();
50 let payload =
51 truncate_lines_with_file(fake_logs, lines, "ops-logs").map_err(|_| {
52 CommandError::new(
53 "failed to write full log output",
54 "LOG_WRITE_FAILED",
55 "Check disk permissions and retry.",
56 )
57 })?;
58
59 Ok(
60 CommandOutput::new(json!(payload)).next_action(NextAction::new(
61 "ops logs <source> [--lines <lines>] [--follow]",
62 "Adjust line count or follow logs",
63 )),
64 )
65 }),
66 );
67
68 let run = cli.run_env();
69 println!("{}", run.to_json());
70 std::process::exit(run.exit_code());
71}Sourcepub fn run_env(&self) -> Execution
pub fn run_env(&self) -> Execution
Examples found in repository?
examples/ops.rs (line 68)
7fn main() {
8 let cli = AgentCli::new("ops", "Agent-native operations CLI")
9 .version(env!("CARGO_PKG_VERSION"))
10 .root_field("health", json!({ "server": "ok", "worker": "ok" }))
11 .command(
12 Command::new("status", "Show system health")
13 .usage("ops status")
14 .handler(|_req, _ctx| {
15 Ok(CommandOutput::new(json!({
16 "healthy": true,
17 "queue_depth": 0
18 }))
19 .next_action(NextAction::new("ops status", "Re-check status"))
20 .next_action(
21 NextAction::new("ops logs <source> [--lines <lines>]", "Inspect logs")
22 .with_param(
23 "source",
24 ActionParam::new()
25 .enum_values(["worker", "errors", "server"])
26 .default("worker"),
27 )
28 .with_param(
29 "lines",
30 ActionParam::new()
31 .description("Number of lines to show")
32 .default(20),
33 ),
34 ))
35 }),
36 )
37 .command(
38 Command::new("logs", "View logs with context-safe truncation")
39 .usage("ops logs <source> [--lines <lines>] [--follow]")
40 .handler(|req, _ctx| {
41 let source = req.arg(0).unwrap_or("worker");
42 let lines = req
43 .flag("lines")
44 .and_then(|value| value.parse::<usize>().ok())
45 .unwrap_or(20);
46
47 let fake_logs = (0..120)
48 .map(|idx| format!("[{source}] line-{idx}"))
49 .collect::<Vec<_>>();
50 let payload =
51 truncate_lines_with_file(fake_logs, lines, "ops-logs").map_err(|_| {
52 CommandError::new(
53 "failed to write full log output",
54 "LOG_WRITE_FAILED",
55 "Check disk permissions and retry.",
56 )
57 })?;
58
59 Ok(
60 CommandOutput::new(json!(payload)).next_action(NextAction::new(
61 "ops logs <source> [--lines <lines>] [--follow]",
62 "Adjust line count or follow logs",
63 )),
64 )
65 }),
66 );
67
68 let run = cli.run_env();
69 println!("{}", run.to_json());
70 std::process::exit(run.exit_code());
71}pub fn run_env_with_context(&self, context: &mut ExecutionContext) -> Execution
pub fn run_argv<I, S>(&self, args: I) -> Execution
pub fn run_argv_with_context<I, S>( &self, args: I, context: &mut ExecutionContext, ) -> Execution
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AgentCli
impl !RefUnwindSafe for AgentCli
impl Send for AgentCli
impl Sync for AgentCli
impl Unpin for AgentCli
impl UnsafeUnpin for AgentCli
impl !UnwindSafe for AgentCli
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more