diff --git a/Cargo.lock b/Cargo.lock index 1fd9d2e..a271023 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,91 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "colored" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" +dependencies = [ + "lazy_static", + "windows-sys", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + [[package]] name = "thp" version = "0.0.9" +dependencies = [ + "colored", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" diff --git a/Cargo.toml b/Cargo.toml index 2afff01..7a7ae36 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +colored = "2.1.0" diff --git a/src/cli/help.rs b/src/cli/help.rs index 9668e99..f393cf4 100644 --- a/src/cli/help.rs +++ b/src/cli/help.rs @@ -1,7 +1,5 @@ use crate::cli::HELP_TEXT; - pub fn help_command(options: &Vec) { println!("{}", HELP_TEXT); } - diff --git a/src/cli/mod.rs b/src/cli/mod.rs index ae1f884..87f3355 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -3,25 +3,27 @@ mod types; use types::{Command, CommandType}; +use colored::*; + pub const HELP_TEXT: &str = r#" Usage: `thp [command] [options]` Commands - c _file_ Compiles `file` in-place - f _file_ Formats `file` - r Starts the REPL + c _file_ Compiles `file` in-place + f _file_ Formats `file` + r Starts the REPL - init Initializes a new project in the current directory - build Builds the project - fmt Formats all files in the project - watch, w Starts compilation of the project in watch mode + init Initializes a new project in the current directory + build Builds the project + fmt Formats all files in the project + watch, w Starts compilation of the project in watch mode - help, h Print this message & exit + help, h Print this message & exit General options - -h, --help Print command-specific usage + -h, --help Print command-specific usage "#; fn get_copyright() -> String { @@ -34,9 +36,9 @@ pub fn run_cli() { Ok(c) => c, Err(reason) => { println!("{}", HELP_TEXT); - println!("Error: {}", reason); + println!("{}: {}", "error".red(), reason); return; - }, + } }; command.run(); @@ -58,10 +60,7 @@ fn parse_args() -> Result { if arg.starts_with('-') { options.push(arg); } else { - return Err(format!( - "Unexpected command `{}` after the options", - arg - )); + return Err(format!("Unexpected command `{}` after the options", arg)); } } @@ -75,12 +74,10 @@ fn parse_args() -> Result { "fmt" => CommandType::Fmt, "watch" | "w" => CommandType::Watch, "help" | "h" => CommandType::Help, - _ => return Err(format!("Unknown command: {}", command)), + _ => return Err(format!("Unknown command `{}`", command)), }, None => CommandType::None, }; Ok(Command { command, options }) } - - diff --git a/src/cli/types.rs b/src/cli/types.rs index 3d358d6..2dacdde 100644 --- a/src/cli/types.rs +++ b/src/cli/types.rs @@ -17,7 +17,6 @@ pub enum CommandType { None, } - impl Command { pub fn run(&self) { println!("Running command! {:?}", self);