mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-20 20:55:50 +00:00
Move subcommand branching into Options struct
This commit is contained in:
18
src/bin.rs
18
src/bin.rs
@@ -3,21 +3,7 @@ use std::{env, panic, process};
|
||||
use backtrace::Backtrace;
|
||||
use structopt::StructOpt;
|
||||
|
||||
use librojo::cli::{self, GlobalOptions, Options, Subcommand};
|
||||
|
||||
fn run(global: GlobalOptions, subcommand: Subcommand) -> anyhow::Result<()> {
|
||||
match subcommand {
|
||||
Subcommand::Init(subcommand) => subcommand.run()?,
|
||||
Subcommand::Serve(serve_options) => cli::serve(global, serve_options)?,
|
||||
Subcommand::Build(subcommand) => subcommand.run()?,
|
||||
Subcommand::Upload(upload_options) => cli::upload(upload_options)?,
|
||||
Subcommand::FmtProject(subcommand) => subcommand.run()?,
|
||||
Subcommand::Doc(subcommand) => subcommand.run()?,
|
||||
Subcommand::Plugin(subcommand) => subcommand.run()?,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
use librojo::cli::Options;
|
||||
|
||||
fn main() {
|
||||
panic::set_hook(Box::new(|panic_info| {
|
||||
@@ -82,7 +68,7 @@ fn main() {
|
||||
.write_style(options.global.color.into())
|
||||
.init();
|
||||
|
||||
if let Err(err) = run(options.global, options.subcommand) {
|
||||
if let Err(err) = options.run() {
|
||||
log::error!("{:?}", err);
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
@@ -41,6 +41,20 @@ pub struct Options {
|
||||
pub subcommand: Subcommand,
|
||||
}
|
||||
|
||||
impl Options {
|
||||
pub fn run(self) -> anyhow::Result<()> {
|
||||
match self.subcommand {
|
||||
Subcommand::Init(subcommand) => subcommand.run(),
|
||||
Subcommand::Serve(serve_options) => serve(self.global, serve_options),
|
||||
Subcommand::Build(subcommand) => subcommand.run(),
|
||||
Subcommand::Upload(upload_options) => upload(upload_options),
|
||||
Subcommand::FmtProject(subcommand) => subcommand.run(),
|
||||
Subcommand::Doc(subcommand) => subcommand.run(),
|
||||
Subcommand::Plugin(subcommand) => subcommand.run(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct GlobalOptions {
|
||||
/// Sets verbosity level. Can be specified multiple times.
|
||||
|
||||
Reference in New Issue
Block a user