Skip to main content

espforge_lib/cli/
mod.rs

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