command_stream/commands/
exit.rs1use crate::commands::CommandContext;
4use crate::utils::CommandResult;
5
6pub async fn exit(ctx: CommandContext) -> CommandResult {
11 let code: i32 = ctx.args.first().and_then(|s| s.parse().ok()).unwrap_or(0);
12
13 CommandResult::error_with_code("", code)
14}
15
16#[cfg(test)]
17mod tests {
18 use super::*;
19
20 #[tokio::test]
21 async fn test_exit_default() {
22 let ctx = CommandContext::new(vec![]);
23 let result = exit(ctx).await;
24 assert_eq!(result.code, 0);
25 }
26
27 #[tokio::test]
28 async fn test_exit_with_code() {
29 let ctx = CommandContext::new(vec!["42".to_string()]);
30 let result = exit(ctx).await;
31 assert_eq!(result.code, 42);
32 }
33}