Compare commits
No commits in common. "09c267139db983c5fceceac34a7d2559f5391179" and "f6c1664816c32c3a5354b7fc9e415f8eb4196fb8" have entirely different histories.
09c267139d
...
f6c1664816
85
Cargo.lock
generated
85
Cargo.lock
generated
@ -2,91 +2,6 @@
|
||||
# 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"
|
||||
|
@ -7,4 +7,3 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
colored = "2.1.0"
|
||||
|
@ -1,10 +1,7 @@
|
||||
use crate::cli::get_help_text;
|
||||
use colored::*;
|
||||
use crate::cli::HELP_TEXT;
|
||||
|
||||
|
||||
pub fn help_command(options: &Vec<String>) {
|
||||
println!("{}", get_help_text());
|
||||
|
||||
if options.len() > 0 {
|
||||
println!("{}: {}", "warning".yellow(), "The help command doesn't take any options.");
|
||||
}
|
||||
println!("{}", HELP_TEXT);
|
||||
}
|
||||
|
||||
|
@ -1,38 +1,30 @@
|
||||
mod help;
|
||||
mod types;
|
||||
mod empty;
|
||||
|
||||
use types::{Command, CommandType};
|
||||
|
||||
use colored::*;
|
||||
|
||||
pub fn get_help_text() -> String {
|
||||
format!(
|
||||
r#"
|
||||
pub const HELP_TEXT: &str = r#"
|
||||
Usage: `thp [command] [options]`
|
||||
|
||||
Commands
|
||||
|
||||
c {0} Compiles {0} in-place
|
||||
f {0} Formats {0}
|
||||
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
|
||||
"#,
|
||||
"_file_".green()
|
||||
)
|
||||
}
|
||||
-h, --help Print command-specific usage
|
||||
"#;
|
||||
|
||||
fn get_version() -> String {
|
||||
fn get_copyright() -> String {
|
||||
let crate_version = env!("CARGO_PKG_VERSION");
|
||||
format!("The THP compiler, linter & formatter, v{}", crate_version)
|
||||
}
|
||||
@ -41,10 +33,10 @@ pub fn run_cli() {
|
||||
let command = match parse_args() {
|
||||
Ok(c) => c,
|
||||
Err(reason) => {
|
||||
println!("{}", get_help_text());
|
||||
println!("{}: {}", "error".on_red(), reason);
|
||||
println!("{}", HELP_TEXT);
|
||||
println!("Error: {}", reason);
|
||||
return;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
command.run();
|
||||
@ -66,7 +58,10 @@ fn parse_args() -> Result<Command, String> {
|
||||
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
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,10 +75,12 @@ fn parse_args() -> Result<Command, String> {
|
||||
"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 })
|
||||
}
|
||||
|
||||
|
||||
|
@ -17,19 +17,16 @@ pub enum CommandType {
|
||||
None,
|
||||
}
|
||||
|
||||
|
||||
impl Command {
|
||||
pub fn run(&self) {
|
||||
println!("Running command! {:?}", self);
|
||||
self.command.run(&self.options);
|
||||
}
|
||||
}
|
||||
|
||||
impl CommandType {
|
||||
pub fn run(&self, options: &Vec<String>) {
|
||||
match self {
|
||||
CommandType::Help => super::help::help_command(options),
|
||||
_ => {
|
||||
println!("Not implemented yet! {:?} {:?}", self, options);
|
||||
}
|
||||
}
|
||||
println!("Running command! {:?}", self)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user