mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-24 06:35:39 +00:00
Refactor entrypoint to be a bit easier to read
This commit is contained in:
@@ -5,7 +5,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use log::error;
|
use log::error;
|
||||||
use clap::clap_app;
|
use clap::{clap_app, ArgMatches};
|
||||||
|
|
||||||
use librojo::commands;
|
use librojo::commands;
|
||||||
|
|
||||||
@@ -55,117 +55,125 @@ fn main() {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// `get_matches` consumes self for some reason.
|
// `get_matches` consumes our App, but we might need it in the 'help' case.
|
||||||
let matches = app.clone().get_matches();
|
let matches = app.clone().get_matches();
|
||||||
|
|
||||||
match matches.subcommand() {
|
match matches.subcommand() {
|
||||||
("init", Some(sub_matches)) => {
|
("init", Some(sub_matches)) => start_init(sub_matches),
|
||||||
let fuzzy_project_path = make_path_absolute(Path::new(sub_matches.value_of("PATH").unwrap_or("")));
|
("serve", Some(sub_matches)) => start_serve(sub_matches),
|
||||||
let kind = sub_matches.value_of("kind");
|
("build", Some(sub_matches)) => start_build(sub_matches),
|
||||||
|
("upload", Some(sub_matches)) => start_upload(sub_matches),
|
||||||
let options = commands::InitOptions {
|
|
||||||
fuzzy_project_path,
|
|
||||||
kind,
|
|
||||||
};
|
|
||||||
|
|
||||||
match commands::init(&options) {
|
|
||||||
Ok(_) => {},
|
|
||||||
Err(e) => {
|
|
||||||
error!("{}", e);
|
|
||||||
process::exit(1);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
("serve", Some(sub_matches)) => {
|
|
||||||
let fuzzy_project_path = match sub_matches.value_of("PROJECT") {
|
|
||||||
Some(v) => make_path_absolute(Path::new(v)),
|
|
||||||
None => std::env::current_dir().unwrap(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let port = match sub_matches.value_of("port") {
|
|
||||||
Some(v) => match v.parse::<u16>() {
|
|
||||||
Ok(port) => Some(port),
|
|
||||||
Err(_) => {
|
|
||||||
error!("Invalid port {}", v);
|
|
||||||
process::exit(1);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
None => None,
|
|
||||||
};
|
|
||||||
|
|
||||||
let options = commands::ServeOptions {
|
|
||||||
fuzzy_project_path,
|
|
||||||
port,
|
|
||||||
};
|
|
||||||
|
|
||||||
match commands::serve(&options) {
|
|
||||||
Ok(_) => {},
|
|
||||||
Err(e) => {
|
|
||||||
error!("{}", e);
|
|
||||||
process::exit(1);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
("build", Some(sub_matches)) => {
|
|
||||||
let fuzzy_project_path = match sub_matches.value_of("PROJECT") {
|
|
||||||
Some(v) => make_path_absolute(Path::new(v)),
|
|
||||||
None => std::env::current_dir().unwrap(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let output_file = make_path_absolute(Path::new(sub_matches.value_of("output").unwrap()));
|
|
||||||
|
|
||||||
let options = commands::BuildOptions {
|
|
||||||
fuzzy_project_path,
|
|
||||||
output_file,
|
|
||||||
output_kind: None, // TODO: Accept from argument
|
|
||||||
};
|
|
||||||
|
|
||||||
match commands::build(&options) {
|
|
||||||
Ok(_) => {},
|
|
||||||
Err(e) => {
|
|
||||||
error!("{}", e);
|
|
||||||
process::exit(1);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
("upload", Some(sub_matches)) => {
|
|
||||||
let fuzzy_project_path = match sub_matches.value_of("PROJECT") {
|
|
||||||
Some(v) => make_path_absolute(Path::new(v)),
|
|
||||||
None => std::env::current_dir().unwrap(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let kind = sub_matches.value_of("kind");
|
|
||||||
let security_cookie = sub_matches.value_of("cookie").unwrap();
|
|
||||||
|
|
||||||
let asset_id: u64 = {
|
|
||||||
let arg = sub_matches.value_of("asset_id").unwrap();
|
|
||||||
|
|
||||||
match arg.parse() {
|
|
||||||
Ok(v) => v,
|
|
||||||
Err(_) => {
|
|
||||||
error!("Invalid place ID {}", arg);
|
|
||||||
process::exit(1);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let options = commands::UploadOptions {
|
|
||||||
fuzzy_project_path,
|
|
||||||
security_cookie: security_cookie.to_string(),
|
|
||||||
asset_id,
|
|
||||||
kind,
|
|
||||||
};
|
|
||||||
|
|
||||||
match commands::upload(&options) {
|
|
||||||
Ok(_) => {},
|
|
||||||
Err(e) => {
|
|
||||||
error!("{}", e);
|
|
||||||
process::exit(1);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => {
|
_ => {
|
||||||
app.print_help().expect("Could not print help text to stdout!");
|
app.print_help().expect("Could not print help text to stdout!");
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn start_init(sub_matches: &ArgMatches) {
|
||||||
|
let fuzzy_project_path = make_path_absolute(Path::new(sub_matches.value_of("PATH").unwrap_or("")));
|
||||||
|
let kind = sub_matches.value_of("kind");
|
||||||
|
|
||||||
|
let options = commands::InitOptions {
|
||||||
|
fuzzy_project_path,
|
||||||
|
kind,
|
||||||
|
};
|
||||||
|
|
||||||
|
match commands::init(&options) {
|
||||||
|
Ok(_) => {},
|
||||||
|
Err(e) => {
|
||||||
|
error!("{}", e);
|
||||||
|
process::exit(1);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn start_serve(sub_matches: &ArgMatches) {
|
||||||
|
let fuzzy_project_path = match sub_matches.value_of("PROJECT") {
|
||||||
|
Some(v) => make_path_absolute(Path::new(v)),
|
||||||
|
None => std::env::current_dir().unwrap(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let port = match sub_matches.value_of("port") {
|
||||||
|
Some(v) => match v.parse::<u16>() {
|
||||||
|
Ok(port) => Some(port),
|
||||||
|
Err(_) => {
|
||||||
|
error!("Invalid port {}", v);
|
||||||
|
process::exit(1);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let options = commands::ServeOptions {
|
||||||
|
fuzzy_project_path,
|
||||||
|
port,
|
||||||
|
};
|
||||||
|
|
||||||
|
match commands::serve(&options) {
|
||||||
|
Ok(_) => {},
|
||||||
|
Err(e) => {
|
||||||
|
error!("{}", e);
|
||||||
|
process::exit(1);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn start_build(sub_matches: &ArgMatches) {
|
||||||
|
let fuzzy_project_path = match sub_matches.value_of("PROJECT") {
|
||||||
|
Some(v) => make_path_absolute(Path::new(v)),
|
||||||
|
None => std::env::current_dir().unwrap(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let output_file = make_path_absolute(Path::new(sub_matches.value_of("output").unwrap()));
|
||||||
|
|
||||||
|
let options = commands::BuildOptions {
|
||||||
|
fuzzy_project_path,
|
||||||
|
output_file,
|
||||||
|
output_kind: None, // TODO: Accept from argument
|
||||||
|
};
|
||||||
|
|
||||||
|
match commands::build(&options) {
|
||||||
|
Ok(_) => {},
|
||||||
|
Err(e) => {
|
||||||
|
error!("{}", e);
|
||||||
|
process::exit(1);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn start_upload(sub_matches: &ArgMatches) {
|
||||||
|
let fuzzy_project_path = match sub_matches.value_of("PROJECT") {
|
||||||
|
Some(v) => make_path_absolute(Path::new(v)),
|
||||||
|
None => std::env::current_dir().unwrap(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let kind = sub_matches.value_of("kind");
|
||||||
|
let security_cookie = sub_matches.value_of("cookie").unwrap();
|
||||||
|
|
||||||
|
let asset_id: u64 = {
|
||||||
|
let arg = sub_matches.value_of("asset_id").unwrap();
|
||||||
|
|
||||||
|
match arg.parse() {
|
||||||
|
Ok(v) => v,
|
||||||
|
Err(_) => {
|
||||||
|
error!("Invalid place ID {}", arg);
|
||||||
|
process::exit(1);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let options = commands::UploadOptions {
|
||||||
|
fuzzy_project_path,
|
||||||
|
security_cookie: security_cookie.to_string(),
|
||||||
|
asset_id,
|
||||||
|
kind,
|
||||||
|
};
|
||||||
|
|
||||||
|
match commands::upload(&options) {
|
||||||
|
Ok(_) => {},
|
||||||
|
Err(e) => {
|
||||||
|
error!("{}", e);
|
||||||
|
process::exit(1);
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user