forked from rojo-rbx/rojo
Switch everything to StructOpt (#277)
* Add types for Rojo's subcommands * Flesh out CLI types * Port everything to structopt instead of clap
This commit is contained in:
committed by
GitHub
parent
8b1e85fbb4
commit
47c7f63d75
@@ -1,17 +1,12 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use failure::Fail;
|
||||
|
||||
use crate::project::{Project, ProjectInitError};
|
||||
use crate::{
|
||||
cli::{InitCommand, InitKind},
|
||||
project::{Project, ProjectInitError},
|
||||
};
|
||||
|
||||
#[derive(Debug, Fail)]
|
||||
pub enum InitError {
|
||||
#[fail(
|
||||
display = "Invalid project kind '{}', valid kinds are 'place' and 'model'",
|
||||
_0
|
||||
)]
|
||||
InvalidKind(String),
|
||||
|
||||
#[fail(display = "Project init error: {}", _0)]
|
||||
ProjectInitError(#[fail(cause)] ProjectInitError),
|
||||
}
|
||||
@@ -20,23 +15,16 @@ impl_from!(InitError {
|
||||
ProjectInitError => ProjectInitError,
|
||||
});
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct InitOptions<'a> {
|
||||
pub fuzzy_project_path: PathBuf,
|
||||
pub kind: Option<&'a str>,
|
||||
}
|
||||
|
||||
pub fn init(options: &InitOptions) -> Result<(), InitError> {
|
||||
pub fn init(options: InitCommand) -> Result<(), InitError> {
|
||||
let (project_path, project_kind) = match options.kind {
|
||||
Some("place") | None => {
|
||||
let path = Project::init_place(&options.fuzzy_project_path)?;
|
||||
InitKind::Place => {
|
||||
let path = Project::init_place(&options.path)?;
|
||||
(path, "place")
|
||||
}
|
||||
Some("model") => {
|
||||
let path = Project::init_model(&options.fuzzy_project_path)?;
|
||||
InitKind::Model => {
|
||||
let path = Project::init_model(&options.path)?;
|
||||
(path, "model")
|
||||
}
|
||||
Some(invalid) => return Err(InitError::InvalidKind(invalid.to_string())),
|
||||
};
|
||||
|
||||
println!(
|
||||
|
||||
Reference in New Issue
Block a user