mod build;
mod check;
mod fetch;
mod new;
mod reporter;
use std::process::ExitCode;
use clap::{Parser, Subcommand};
use crate::build::BuildArgs;
use crate::check::CheckArgs;
use crate::fetch::FetchArgs;
use crate::new::NewArgs;
#[derive(Parser)]
#[command(name = "csti", version, about)]
struct Cli {
#[command(subcommand)]
command: Command,
}
#[derive(Subcommand)]
enum Command {
Build(BuildArgs),
Check(CheckArgs),
Fetch(FetchArgs),
New(NewArgs),
}
#[tokio::main]
async fn main() -> ExitCode {
let cli = Cli::parse();
let result = match cli.command {
Command::Build(args) => build::run(args).await,
Command::Check(args) => check::run(args).await,
Command::Fetch(args) => fetch::run(args).await,
Command::New(args) => new::run(args),
};
match result {
Ok(()) => ExitCode::SUCCESS,
Err(err) => {
eprintln!("error: {err}");
ExitCode::FAILURE
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn build_requires_linux_checkout() {
assert!(Cli::try_parse_from(["csti", "build"]).is_err());
assert!(Cli::try_parse_from(["csti", "build", "--linux", "/src/linux"]).is_ok());
}
#[test]
fn check_needs_no_linux_checkout() {
assert!(Cli::try_parse_from(["csti", "check"]).is_ok());
assert!(Cli::try_parse_from(["csti", "check", "--linux", "/src/linux"]).is_ok());
assert!(Cli::try_parse_from(["csti", "check", "--skip-remoteproc-check"]).is_err());
}
#[test]
fn new_needs_a_chip_unless_interactive() {
assert!(Cli::try_parse_from(["csti", "new", "demo"]).is_err());
assert!(Cli::try_parse_from(["csti", "new", "demo", "--chip", "stm32mp257f"]).is_ok());
assert!(
Cli::try_parse_from([
"csti", "new", "demo", "--chip", "mimx9352", "--tee", "--hmi"
])
.is_ok()
);
assert!(Cli::try_parse_from(["csti", "new", "demo", "--chip", "mimx95"]).is_err());
assert!(Cli::try_parse_from(["csti", "new", "-i"]).is_ok());
}
}