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 crate::examples::ExamplesArgs;
10use crate::examples::execute_noninteractive;
11use commands::{compile, doctor, examples};
12
13#[derive(Parser)]
14#[command(version, about = "Example tool with a compile subcommand")]
15pub struct Cli {
16    #[command(subcommand)]
17    command: Commands,
18}
19
20#[derive(Subcommand)]
21enum Commands {
22    Compile {
23        file: PathBuf,
24    },
25    Examples {
26        #[arg(default_value = "")]
27        name: String,
28        #[arg(long, short = 'n')]
29        project_name: Option<String>,
30        #[arg(long, short = 'c')]
31        chip: Option<String>,
32    },
33    Example {
34        name: String,
35        #[arg(long, short = 'n')]
36        project_name: Option<String>,
37        #[arg(long, short = 'c')]
38        chip: Option<String>,
39    },
40    Doctor,
41}
42
43impl Cli {
44    pub fn execute(self) -> Result<()> {
45        match self.command {
46            Commands::Compile { file } => compile::execute(&file),
47            Commands::Examples {
48                name,
49                project_name,
50                chip,
51            } => examples::execute(ExamplesArgs {
52                name,
53                project_name,
54                chip,
55            }),
56            Commands::Example {
57                name,
58                project_name,
59                chip,
60            } => execute_noninteractive(ExamplesArgs {
61                name,
62                project_name,
63                chip,
64            }),
65            Commands::Doctor => doctor::execute(),
66        }
67    }
68}