mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-25 07:06:12 +00:00
Stub out new 'init' command
This commit is contained in:
@@ -32,6 +32,7 @@ fn main() {
|
|||||||
(@subcommand init =>
|
(@subcommand init =>
|
||||||
(about: "Creates a new Rojo project")
|
(about: "Creates a new Rojo project")
|
||||||
(@arg PATH: "Path to the place to create the project. Defaults to the current directory.")
|
(@arg PATH: "Path to the place to create the project. Defaults to the current directory.")
|
||||||
|
(@arg kind: --kind +takes_value "The kind of project to create, 'place' or 'model'. Defaults to place.")
|
||||||
)
|
)
|
||||||
|
|
||||||
(@subcommand serve =>
|
(@subcommand serve =>
|
||||||
@@ -59,10 +60,21 @@ fn main() {
|
|||||||
|
|
||||||
match matches.subcommand() {
|
match matches.subcommand() {
|
||||||
("init", Some(sub_matches)) => {
|
("init", Some(sub_matches)) => {
|
||||||
let project_path = Path::new(sub_matches.value_of("PATH").unwrap_or("."));
|
let fuzzy_project_path = make_path_absolute(Path::new(sub_matches.value_of("PATH").unwrap_or(".")));
|
||||||
let full_path = make_path_absolute(project_path);
|
let kind = sub_matches.value_of("kind");
|
||||||
|
|
||||||
commands::init(&full_path);
|
let options = commands::InitOptions {
|
||||||
|
fuzzy_project_path,
|
||||||
|
kind,
|
||||||
|
};
|
||||||
|
|
||||||
|
match commands::init(&options) {
|
||||||
|
Ok(_) => {},
|
||||||
|
Err(e) => {
|
||||||
|
error!("{}", e);
|
||||||
|
process::exit(1);
|
||||||
|
},
|
||||||
|
}
|
||||||
},
|
},
|
||||||
("serve", Some(sub_matches)) => {
|
("serve", Some(sub_matches)) => {
|
||||||
let fuzzy_project_path = match sub_matches.value_of("PROJECT") {
|
let fuzzy_project_path = match sub_matches.value_of("PROJECT") {
|
||||||
|
|||||||
@@ -1,16 +1,46 @@
|
|||||||
use std::path::PathBuf;
|
use std::{
|
||||||
use std::process;
|
path::PathBuf,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::project::Project;
|
use failure::Fail;
|
||||||
|
|
||||||
pub fn init(project_path: &PathBuf) {
|
use crate::project::{Project, ProjectInitError};
|
||||||
match Project::init(project_path) {
|
|
||||||
Ok(_) => {
|
#[derive(Debug, Fail)]
|
||||||
println!("Created new empty project at {}", project_path.display());
|
pub enum InitError {
|
||||||
},
|
#[fail(display = "Invalid project kind '{}', valid kinds are 'place' and 'model'", _0)]
|
||||||
Err(e) => {
|
InvalidKind(String),
|
||||||
error!("Failed to create new project.\n{}", e);
|
|
||||||
process::exit(1);
|
#[fail(display = "Project init error: {}", _0)]
|
||||||
},
|
ProjectInitError(#[fail(cause)] ProjectInitError)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ProjectInitError> for InitError {
|
||||||
|
fn from(error: ProjectInitError) -> InitError {
|
||||||
|
InitError::ProjectInitError(error)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct InitOptions<'a> {
|
||||||
|
pub fuzzy_project_path: PathBuf,
|
||||||
|
pub kind: Option<&'a str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init(options: &InitOptions) -> Result<(), InitError> {
|
||||||
|
let (project_path, project_kind) = match options.kind {
|
||||||
|
Some("place") | None => {
|
||||||
|
let path = Project::init_place(&options.fuzzy_project_path)?;
|
||||||
|
(path, "place")
|
||||||
|
},
|
||||||
|
Some("model") => {
|
||||||
|
let path = Project::init_model(&options.fuzzy_project_path)?;
|
||||||
|
(path, "model")
|
||||||
|
},
|
||||||
|
Some(invalid) => return Err(InitError::InvalidKind(invalid.to_string())),
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("Created new {} project at {}", project_kind, project_path.display());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -180,7 +180,11 @@ pub struct Project {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Project {
|
impl Project {
|
||||||
pub fn init(_project_folder_location: &Path) -> Result<(), ProjectInitError> {
|
pub fn init_place(_project_fuzzy_location: &Path) -> Result<PathBuf, ProjectInitError> {
|
||||||
|
unimplemented!();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_model(_project_fuzzy_location: &Path) -> Result<PathBuf, ProjectInitError> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user