#![forbid(unsafe_code)]
#![warn(missing_docs)]
pub mod cli;
pub mod cmd;
pub mod console;
pub mod error;
pub mod stubs;
pub use cli::{Cli, Command as CliCommand};
pub use console::{Command, CommandSignature, Console};
pub use error::CliError;
pub async fn run<I, S>(args: I) -> Result<i32, CliError>
where
I: IntoIterator<Item = S>,
S: Into<std::ffi::OsString> + Clone,
{
use clap::Parser;
let cli = Cli::parse_from(args);
cli.execute().await
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_run_no_args_returns_ok() {
let result = run(vec!["sz-rust"]).await;
assert!(result.is_ok());
assert_eq!(result.unwrap(), 0);
}
#[tokio::test]
#[allow(clippy::await_holding_lock)]
async fn test_run_cache_clear_command() {
let _lock = crate::cmd::test_support::acquire_global_lock();
let temp = tempfile::tempdir().expect("tempdir failed");
let original = std::env::current_dir().expect("current_dir failed");
std::env::set_current_dir(temp.path()).expect("set_current_dir failed");
let result = run(vec!["sz-rust", "cache:clear"]).await;
let restore = std::env::set_current_dir(&original);
assert!(restore.is_ok(), "恢复工作目录失败");
assert!(result.is_ok());
}
}