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>) {
|
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 help;
|
||||||
mod types;
|
mod types;
|
||||||
|
mod empty;
|
||||||
|
|
||||||
use types::{Command, CommandType};
|
use types::{Command, CommandType};
|
||||||
|
|
||||||
use colored::*;
|
use colored::*;
|
||||||
|
|
||||||
pub const HELP_TEXT: &str = r#"
|
pub fn get_help_text() -> String {
|
||||||
|
format!(
|
||||||
|
r#"
|
||||||
Usage: `thp [command] [options]`
|
Usage: `thp [command] [options]`
|
||||||
|
|
||||||
Commands
|
Commands
|
||||||
|
|
||||||
c _file_ Compiles `file` in-place
|
c {0} Compiles {0} in-place
|
||||||
f _file_ Formats `file`
|
f {0} Formats {0}
|
||||||
r Starts the REPL
|
r Starts the REPL
|
||||||
|
|
||||||
init Initializes a new project in the current directory
|
init Initializes a new project in the current directory
|
||||||
@ -24,9 +27,12 @@ Commands
|
|||||||
General options
|
General options
|
||||||
|
|
||||||
-h, --help Print command-specific usage
|
-h, --help Print command-specific usage
|
||||||
"#;
|
"#,
|
||||||
|
"_file_".green()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fn get_copyright() -> String {
|
fn get_version() -> String {
|
||||||
let crate_version = env!("CARGO_PKG_VERSION");
|
let crate_version = env!("CARGO_PKG_VERSION");
|
||||||
format!("The THP compiler, linter & formatter, v{}", crate_version)
|
format!("The THP compiler, linter & formatter, v{}", crate_version)
|
||||||
}
|
}
|
||||||
@ -35,8 +41,8 @@ pub fn run_cli() {
|
|||||||
let command = match parse_args() {
|
let command = match parse_args() {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err(reason) => {
|
Err(reason) => {
|
||||||
println!("{}", HELP_TEXT);
|
println!("{}", get_help_text());
|
||||||
println!("{}: {}", "error".red(), reason);
|
println!("{}: {}", "error".on_red(), reason);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -19,13 +19,17 @@ pub enum CommandType {
|
|||||||
|
|
||||||
impl Command {
|
impl Command {
|
||||||
pub fn run(&self) {
|
pub fn run(&self) {
|
||||||
println!("Running command! {:?}", self);
|
|
||||||
self.command.run(&self.options);
|
self.command.run(&self.options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CommandType {
|
impl CommandType {
|
||||||
pub fn run(&self, options: &Vec<String>) {
|
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