cargo_program/
lib.rs

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