1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
mod commands;
mod common;
mod error;
use anyhow::Result;
use clap::Clap;
use crate::commands::*;
#[derive(Clap, Debug)]
#[clap(
bin_name = "cargo",
version = clap::crate_version!(),
)]
struct Opts {
#[clap(subcommand)]
command: Util,
}
#[derive(Clap, Debug)]
enum Util {
#[clap(
name = "program",
version = clap::crate_version!(),
)]
Program(ProgramUtil),
}
#[derive(Clap, Debug)]
struct ProgramUtil {
#[clap(subcommand)]
command: Command,
}
#[derive(Clap, Debug)]
enum Command {
New(NewCommand),
Build(BuildCommand),
Run(RunCommand),
Test(TestCommand),
Login(LoginCommand),
Publish(PublishCommand),
}
pub fn run() -> Result<()> {
let opts = Opts::parse();
let Util::Program(ProgramUtil { command }) = opts.command;
match command {
Command::New(command) => command.run(),
Command::Build(command) => command.run(),
Command::Run(command) => command.run(),
Command::Test(command) => command.run(),
Command::Login(command) => command.run(),
Command::Publish(command) => command.run(),
}
}