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
use crate::config::ConfigOverride;
use anchor_client::Cluster;
use anyhow::Result;
use clap::Parser;

mod commands;
pub mod config;
mod errors;
mod path;
mod utils;

pub const VERSION: &str = env!("CARGO_PKG_VERSION");

#[derive(Parser, Debug)]
#[clap(version = VERSION)]
pub struct Opts {
    #[clap(flatten)]
    pub cfg_override: ConfigOverride,

    #[clap(subcommand)]
    command: Command,
}

#[derive(Debug, Parser)]
pub enum Command {
    /// Initializes a dev-tools workspace
    Init,
    /// Prints the address of the dex program
    Instance,
    /// Deploys the dex program to the specified cluster
    Deploy {
        /// The cluster to deploy to
        cluster: Cluster,

        /// The command to run after deploying
        #[clap(long)]
        command: Option<String>,
    },
}

pub fn entry(opts: Opts) -> Result<()> {
    match opts.command {
        Command::Init => commands::init(),
        Command::Instance => commands::instance(),
        Command::Deploy { cluster, command } => {
            commands::deploy(&opts.cfg_override, cluster, command)
        }
    }
}