bricks/cli/
args.rs

1use std::path::PathBuf;
2
3use clap::Parser;
4use clap_derive::{Args, Subcommand};
5
6#[derive(Debug, Subcommand)]
7pub enum SubCommand {
8    /// Build an executable or library
9    Build(BuildCommand),
10
11    /// Build and run the binary directly
12    Run(RunCommand),
13
14    /// Initialize new project
15    Init(InitCommand),
16
17    /// Install required libraries
18    Install(InstallCommand),
19
20    /// Cleans the build directory
21    Clean(CleanCommand),
22}
23
24#[derive(Debug, Args)]
25pub struct BuildCommand {
26    #[arg(long, required = false)]
27    pub force: bool,
28
29    #[arg(long, default_value = "true")]
30    pub emit_compile_commands: bool,
31
32    #[clap(default_value = ".")]
33    pub path: String,
34
35    #[arg(long, required = false)]
36    pub silent: bool,
37}
38
39#[derive(Debug, Args)]
40pub struct RunCommand {
41    #[arg(long, required = false)]
42    pub force: bool,
43
44    #[clap(default_value = ".")]
45    pub path: String,
46}
47
48#[derive(Debug, Args)]
49pub struct InitCommand {
50    pub name: String,
51
52    #[arg(long, required = false)]
53    pub cpp: bool,
54
55    #[arg(long, required = false)]
56    /// Sets this project as lib
57    pub lib: bool,
58}
59
60#[derive(Debug, Args)]
61pub struct CleanCommand {
62    #[clap(default_value = ".")]
63    pub path: String,
64}
65
66#[derive(Debug, Args)]
67pub struct InstallCommand {
68    #[clap(default_value = ".")]
69    pub path: String,
70    #[arg(long, required = false)]
71    pub force: bool,
72    #[arg(long, required = false)]
73    pub silent: bool,
74}
75
76#[derive(Debug, Parser)]
77#[clap(author, version, about)]
78#[command(name = "bricks")]
79#[command(bin_name = "bricks")]
80#[command(styles = CLAP_STYLING)]
81/// build system and package manager for C/C++
82pub struct Args {
83    #[clap(subcommand)]
84    pub sub: SubCommand,
85
86    #[arg(
87        short,
88        long,
89        value_name = "CONFIG PATH",
90        required = false,
91        default_value = "./brick.toml"
92    )]
93    pub config: PathBuf,
94}
95
96pub const CLAP_STYLING: clap::builder::styling::Styles = clap::builder::styling::Styles::styled()
97    .header(
98        anstyle::Style::new()
99            .bold()
100            .fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Magenta))),
101    )
102    .usage(
103        anstyle::Style::new()
104            .bold()
105            .fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Magenta))),
106    )
107    .literal(
108        anstyle::Style::new()
109            .bold()
110            .fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Blue))),
111    );
112// .placeholder(clap_cargo::style::PLACEHOLDER)
113// .error(clap_cargo::style::ERROR)
114// .valid(clap_cargo::style::VALID)
115// .invalid(clap_cargo::style::INVALID);