Use colored for CLI output
This commit is contained in:
parent
f6c1664816
commit
2583c35f21
85
Cargo.lock
generated
85
Cargo.lock
generated
@ -2,6 +2,91 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
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]]
|
[[package]]
|
||||||
name = "thp"
|
name = "thp"
|
||||||
version = "0.0.9"
|
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,3 +7,4 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
colored = "2.1.0"
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
use crate::cli::HELP_TEXT;
|
use crate::cli::HELP_TEXT;
|
||||||
|
|
||||||
|
|
||||||
pub fn help_command(options: &Vec<String>) {
|
pub fn help_command(options: &Vec<String>) {
|
||||||
println!("{}", HELP_TEXT);
|
println!("{}", HELP_TEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@ mod types;
|
|||||||
|
|
||||||
use types::{Command, CommandType};
|
use types::{Command, CommandType};
|
||||||
|
|
||||||
|
use colored::*;
|
||||||
|
|
||||||
pub const HELP_TEXT: &str = r#"
|
pub const HELP_TEXT: &str = r#"
|
||||||
Usage: `thp [command] [options]`
|
Usage: `thp [command] [options]`
|
||||||
|
|
||||||
@ -34,9 +36,9 @@ pub fn run_cli() {
|
|||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err(reason) => {
|
Err(reason) => {
|
||||||
println!("{}", HELP_TEXT);
|
println!("{}", HELP_TEXT);
|
||||||
println!("Error: {}", reason);
|
println!("{}: {}", "error".red(), reason);
|
||||||
return;
|
return;
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
command.run();
|
command.run();
|
||||||
@ -58,10 +60,7 @@ fn parse_args() -> Result<Command, String> {
|
|||||||
if arg.starts_with('-') {
|
if arg.starts_with('-') {
|
||||||
options.push(arg);
|
options.push(arg);
|
||||||
} else {
|
} else {
|
||||||
return Err(format!(
|
return Err(format!("Unexpected command `{}` after the options", arg));
|
||||||
"Unexpected command `{}` after the options",
|
|
||||||
arg
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,12 +74,10 @@ fn parse_args() -> Result<Command, String> {
|
|||||||
"fmt" => CommandType::Fmt,
|
"fmt" => CommandType::Fmt,
|
||||||
"watch" | "w" => CommandType::Watch,
|
"watch" | "w" => CommandType::Watch,
|
||||||
"help" | "h" => CommandType::Help,
|
"help" | "h" => CommandType::Help,
|
||||||
_ => return Err(format!("Unknown command: {}", command)),
|
_ => return Err(format!("Unknown command `{}`", command)),
|
||||||
},
|
},
|
||||||
None => CommandType::None,
|
None => CommandType::None,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Command { command, options })
|
Ok(Command { command, options })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ pub enum CommandType {
|
|||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Command {
|
impl Command {
|
||||||
pub fn run(&self) {
|
pub fn run(&self) {
|
||||||
println!("Running command! {:?}", self);
|
println!("Running command! {:?}", self);
|
||||||
|
Loading…
Reference in New Issue
Block a user