CLI help command
This commit is contained in:
parent
2583c35f21
commit
09c267139d
0
src/cli/empty.rs
Normal file
0
src/cli/empty.rs
Normal file
@ -1,5 +1,10 @@
|
||||
use crate::cli::HELP_TEXT;
|
||||
use crate::cli::get_help_text;
|
||||
use colored::*;
|
||||
|
||||
pub fn help_command(options: &Vec<String>) {
|
||||
println!("{}", HELP_TEXT);
|
||||
println!("{}", get_help_text());
|
||||
|
||||
if options.len() > 0 {
|
||||
println!("{}: {}", "warning".yellow(), "The help command doesn't take any options.");
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,20 @@
|
||||
mod help;
|
||||
mod types;
|
||||
mod empty;
|
||||
|
||||
use types::{Command, CommandType};
|
||||
|
||||
use colored::*;
|
||||
|
||||
pub const HELP_TEXT: &str = r#"
|
||||
pub fn get_help_text() -> String {
|
||||
format!(
|
||||
r#"
|
||||
Usage: `thp [command] [options]`
|
||||
|
||||
Commands
|
||||
|
||||
c _file_ Compiles `file` in-place
|
||||
f _file_ Formats `file`
|
||||
c {0} Compiles {0} in-place
|
||||
f {0} Formats {0}
|
||||
r Starts the REPL
|
||||
|
||||
init Initializes a new project in the current directory
|
||||
@ -24,9 +27,12 @@ Commands
|
||||
General options
|
||||
|
||||
-h, --help Print command-specific usage
|
||||
"#;
|
||||
"#,
|
||||
"_file_".green()
|
||||
)
|
||||
}
|
||||
|
||||
fn get_copyright() -> String {
|
||||
fn get_version() -> String {
|
||||
let crate_version = env!("CARGO_PKG_VERSION");
|
||||
format!("The THP compiler, linter & formatter, v{}", crate_version)
|
||||
}
|
||||
@ -35,8 +41,8 @@ pub fn run_cli() {
|
||||
let command = match parse_args() {
|
||||
Ok(c) => c,
|
||||
Err(reason) => {
|
||||
println!("{}", HELP_TEXT);
|
||||
println!("{}: {}", "error".red(), reason);
|
||||
println!("{}", get_help_text());
|
||||
println!("{}: {}", "error".on_red(), reason);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
@ -19,13 +19,17 @@ pub enum CommandType {
|
||||
|
||||
impl Command {
|
||||
pub fn run(&self) {
|
||||
println!("Running command! {:?}", self);
|
||||
self.command.run(&self.options);
|
||||
}
|
||||
}
|
||||
|
||||
impl CommandType {
|
||||
pub fn run(&self, options: &Vec<String>) {
|
||||
println!("Running command! {:?}", self)
|
||||
match self {
|
||||
CommandType::Help => super::help::help_command(options),
|
||||
_ => {
|
||||
println!("Not implemented yet! {:?} {:?}", self, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user