From 498f8fb87f07115a3bba53ff95cf4c834c914da0 Mon Sep 17 00:00:00 2001 From: Araozu Date: Wed, 13 Dec 2023 20:29:04 -0500 Subject: [PATCH] Re-enable compile command --- src/cli/compile.rs | 50 ++++++++++++++++++++++++++++++++++++++++++---- src/cli/types.rs | 1 + 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/cli/compile.rs b/src/cli/compile.rs index 28cdb33..6c63a19 100644 --- a/src/cli/compile.rs +++ b/src/cli/compile.rs @@ -1,7 +1,49 @@ -use crate::cli::{get_help_text, get_version}; use colored::*; -#[derive(Eq, PartialEq, Hash)] -enum CompileOptions { - Help, +pub fn compile_command(arguments: Vec) { + if arguments.is_empty() { + 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() + ) } diff --git a/src/cli/types.rs b/src/cli/types.rs index 05e80bb..91c8447 100644 --- a/src/cli/types.rs +++ b/src/cli/types.rs @@ -15,6 +15,7 @@ impl CommandType { pub fn run(&self, options: Vec) { match self { CommandType::Help => super::help::help_command(options), + CommandType::Compile => super::compile::compile_command(options), CommandType::None => super::empty::empty_command(options), _ => { println!("Not implemented yet! {:?} {:?}", self, options);