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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
use anyhow::Result;
use clap::Parser;
mod commands;
mod template;
mod utils;
#[derive(Debug, Parser)]
#[clap(version)]
pub struct Opts {
#[clap(subcommand)]
pub command: Command,
}
#[derive(Debug, Parser)]
pub enum Command {
/// Build a collection from the workspace
Build {
/// The name of the collection
name: String,
},
/// Serves all collections from the workspace
Serve {
/// The name of the collection
name: String,
/// Address that will be used for the server once running.
#[clap(short, long)]
address: Option<String>,
/// Port that wuill be used for the server once running.
#[clap(short, long)]
port: Option<u16>,
/// Protocol that wuill be used for the server once running.
#[clap(long)]
protocol: Option<String>,
},
/// Runs the test suite for the workspace
Test,
/// Deploys a workspace using shuttle
Deploy {
/// The name of the collection
name: String,
/// The name of the project in shuttle
project: String,
},
/// Cleans all the temp files
Clean,
/// Initializes a new workspace
Init {
/// The name of the workspace
name: String,
/// Skip writing the files.
#[clap(short, long)]
dry_run: bool,
},
/// Create a new collection in the workspace
New {
name: String,
/// Skip writing the files.
#[clap(short, long)]
dry_run: bool,
},
}
fn process_command(opts: Opts) -> Result<()> {
match &opts.command {
Command::Build { name } => {
commands::build::run(name);
Ok(())
}
Command::Serve {
name,
address,
port,
protocol,
} => {
commands::serve::run(name, address.as_deref(), port.as_ref(), protocol.as_deref());
Ok(())
}
Command::Test => {
commands::test::run();
Ok(())
}
Command::Clean => {
commands::clean::run();
Ok(())
}
Command::Init { name, dry_run } => {
commands::init::run(name, *dry_run);
Ok(())
}
Command::New { name, dry_run } => {
commands::new::run(name, *dry_run);
Ok(())
}
Command::Deploy { name, project } => {
commands::deploy::run(name, project);
Ok(())
}
}
}
pub fn entry(opts: Opts) -> Result<()> {
process_command(opts)
}