espforge_lib/cli/
mod.rs

1use anyhow::Result;
2use clap::{Parser, Subcommand, command};
3use std::path::PathBuf;
4
5pub mod commands;
6pub mod interactive;
7pub mod model;
8
9use commands::compile;
10use commands::examples;
11
12use crate::examples::ExamplesArgs;
13
14#[derive(Parser)]
15#[command(about = "Example tool with a compile subcommand")]
16pub struct Cli {
17    #[command(subcommand)]
18    command: Commands,
19}
20
21#[derive(Subcommand)]
22enum Commands {
23    Compile {
24        file: PathBuf,
25    },
26    Examples {
27        #[arg(default_value = "")]
28        name: String,
29        #[arg(long, short = 'n')]
30        project_name: Option<String>,
31        #[arg(long, short = 'c')]
32        chip: Option<String>,
33    },
34}
35
36impl Cli {
37    pub fn execute(self) -> Result<()> {
38        match self.command {
39            Commands::Compile { file } => compile::execute(&file),
40            Commands::Examples {
41                name,
42                project_name,
43                chip,
44            } => examples::execute(ExamplesArgs {
45                name,
46                project_name,
47                chip,
48            }),
49        }
50    }
51}