Re-enable compile command
This commit is contained in:
parent
3d5c7769e6
commit
498f8fb87f
@ -1,7 +1,49 @@
|
|||||||
use crate::cli::{get_help_text, get_version};
|
|
||||||
use colored::*;
|
use colored::*;
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Hash)]
|
pub fn compile_command(arguments: Vec<String>) {
|
||||||
enum CompileOptions {
|
if arguments.is_empty() {
|
||||||
Help,
|
println!("{}", compile_help());
|
||||||
|
println!("{}: {}", "error".on_red(), "No file specified");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if arguments.len() > 1 {
|
||||||
|
println!("{}", compile_help());
|
||||||
|
println!(
|
||||||
|
"{}: {}",
|
||||||
|
"error".on_red(),
|
||||||
|
"Only a single file can be compiled at a time"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let argument = &arguments[0];
|
||||||
|
if argument.starts_with("-") {
|
||||||
|
let opt_str = argument.as_str();
|
||||||
|
|
||||||
|
println!("{}", compile_help());
|
||||||
|
|
||||||
|
if opt_str != "-h" && opt_str != "--help" {
|
||||||
|
println!(
|
||||||
|
"{}: {}",
|
||||||
|
"error".on_red(),
|
||||||
|
"Invalid option. The compile command only accepts the `-h` or `--help` option"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
crate::file::compile_file(argument);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn compile_help() -> String {
|
||||||
|
format!(
|
||||||
|
r#"Compile a single file in place.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
`thp compile {0}` Compile {0} and output in the same directory
|
||||||
|
`thp compile -h` Print this message & exit
|
||||||
|
"#,
|
||||||
|
"_file_".green()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ impl CommandType {
|
|||||||
pub fn run(&self, options: Vec<String>) {
|
pub fn run(&self, options: Vec<String>) {
|
||||||
match self {
|
match self {
|
||||||
CommandType::Help => super::help::help_command(options),
|
CommandType::Help => super::help::help_command(options),
|
||||||
|
CommandType::Compile => super::compile::compile_command(options),
|
||||||
CommandType::None => super::empty::empty_command(options),
|
CommandType::None => super::empty::empty_command(options),
|
||||||
_ => {
|
_ => {
|
||||||
println!("Not implemented yet! {:?} {:?}", self, options);
|
println!("Not implemented yet! {:?} {:?}", self, options);
|
||||||
|
Loading…
Reference in New Issue
Block a user