From d5371b5dec5fbf6add535d09afbddcb5b180ef85 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 17 Feb 2020 17:14:55 +0100 Subject: Inline help --- crates/ra_cli/src/help.rs | 75 --------------------------------- crates/ra_cli/src/main.rs | 103 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 96 insertions(+), 82 deletions(-) delete mode 100644 crates/ra_cli/src/help.rs (limited to 'crates/ra_cli') diff --git a/crates/ra_cli/src/help.rs b/crates/ra_cli/src/help.rs deleted file mode 100644 index d3c4c7d0b..000000000 --- a/crates/ra_cli/src/help.rs +++ /dev/null @@ -1,75 +0,0 @@ -//! FIXME: write short doc here - -pub const GLOBAL_HELP: &str = "ra-cli - -USAGE: - ra_cli - -FLAGS: - -h, --help Prints help information - -SUBCOMMANDS: - analysis-bench - analysis-stats - highlight - parse - symbols"; - -pub const ANALYSIS_BENCH_HELP: &str = "ra_cli-analysis-bench - -USAGE: - ra_cli analysis-bench [FLAGS] [OPTIONS] [PATH] - -FLAGS: - -h, --help Prints help information - -v, --verbose - -OPTIONS: - --complete Compute completions at this location - --highlight Hightlight this file - -ARGS: - Project to analyse"; - -pub const ANALYSIS_STATS_HELP: &str = "ra-cli-analysis-stats - -USAGE: - ra_cli analysis-stats [FLAGS] [OPTIONS] [PATH] - -FLAGS: - -h, --help Prints help information - --memory-usage - -v, --verbose - -q, --quiet - -OPTIONS: - -o - -ARGS: - "; - -pub const HIGHLIGHT_HELP: &str = "ra-cli-highlight - -USAGE: - ra_cli highlight [FLAGS] - -FLAGS: - -h, --help Prints help information - -r, --rainbow"; - -pub const SYMBOLS_HELP: &str = "ra-cli-symbols - -USAGE: - ra_cli highlight [FLAGS] - -FLAGS: - -h, --help Prints help inforamtion"; - -pub const PARSE_HELP: &str = "ra-cli-parse - -USAGE: - ra_cli parse [FLAGS] - -FLAGS: - -h, --help Prints help inforamtion - --no-dump"; diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs index f0daaaf15..9a7f9724e 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_cli/src/main.rs @@ -2,7 +2,6 @@ mod analysis_stats; mod analysis_bench; -mod help; mod progress_report; use std::{error::Error, fmt::Write, io::Read}; @@ -46,9 +45,20 @@ fn main() -> Result<()> { match subcommand.as_str() { "parse" => { if matches.contains(["-h", "--help"]) { - eprintln!("{}", help::PARSE_HELP); + eprintln!( + "\ +ra-cli-parse + +USAGE: + ra_cli parse [FLAGS] + +FLAGS: + -h, --help Prints help inforamtion + --no-dump" + ); return Ok(()); } + let no_dump = matches.contains("--no-dump"); matches.finish().or_else(handle_extra_flags)?; @@ -61,10 +71,21 @@ fn main() -> Result<()> { } "symbols" => { if matches.contains(["-h", "--help"]) { - eprintln!("{}", help::SYMBOLS_HELP); + eprintln!( + "\ +ra-cli-symbols + +USAGE: + ra_cli highlight [FLAGS] + +FLAGS: + -h, --help Prints help inforamtion" + ); return Ok(()); } + matches.finish().or_else(handle_extra_flags)?; + let file = file()?; for s in file_structure(&file) { println!("{:?}", s); @@ -72,20 +93,51 @@ fn main() -> Result<()> { } "highlight" => { if matches.contains(["-h", "--help"]) { - eprintln!("{}", help::HIGHLIGHT_HELP); + eprintln!( + "\ +ra-cli-highlight + +USAGE: + ra_cli highlight [FLAGS] + +FLAGS: + -h, --help Prints help information + -r, --rainbow" + ); return Ok(()); } + let rainbow_opt = matches.contains(["-r", "--rainbow"]); matches.finish().or_else(handle_extra_flags)?; + let (analysis, file_id) = Analysis::from_single_file(read_stdin()?); let html = analysis.highlight_as_html(file_id, rainbow_opt).unwrap(); println!("{}", html); } "analysis-stats" => { if matches.contains(["-h", "--help"]) { - eprintln!("{}", help::ANALYSIS_STATS_HELP); + eprintln!( + "\ +ra-cli-analysis-stats + +USAGE: + ra_cli analysis-stats [FLAGS] [OPTIONS] [PATH] + +FLAGS: + -h, --help Prints help information + --memory-usage + -v, --verbose + -q, --quiet + +OPTIONS: + -o + +ARGS: + " + ); return Ok(()); } + let verbosity = match ( matches.contains(["-vv", "--spammy"]), matches.contains(["-v", "--verbose"]), @@ -110,6 +162,8 @@ fn main() -> Result<()> { } trailing.pop().unwrap() }; + matches.finish().or_else(handle_extra_flags)?; + analysis_stats::run( verbosity, memory_usage, @@ -121,9 +175,27 @@ fn main() -> Result<()> { } "analysis-bench" => { if matches.contains(["-h", "--help"]) { - eprintln!("{}", help::ANALYSIS_BENCH_HELP); + eprintln!( + "\ +ra_cli-analysis-bench + +USAGE: + ra_cli analysis-bench [FLAGS] [OPTIONS] [PATH] + +FLAGS: + -h, --help Prints help information + -v, --verbose + +OPTIONS: + --complete Compute completions at this location + --highlight Hightlight this file + +ARGS: + Project to analyse" + ); return Ok(()); } + let verbose = matches.contains(["-v", "--verbose"]); let path: String = matches.opt_value_from_str("--path")?.unwrap_or_default(); let highlight_path: Option = matches.opt_value_from_str("--highlight")?; @@ -138,9 +210,26 @@ fn main() -> Result<()> { ), }; matches.finish().or_else(handle_extra_flags)?; + analysis_bench::run(verbose, path.as_ref(), op)?; } - _ => eprintln!("{}", help::GLOBAL_HELP), + _ => eprintln!( + "\ +ra-cli + +USAGE: + ra_cli + +FLAGS: + -h, --help Prints help information + +SUBCOMMANDS: + analysis-bench + analysis-stats + highlight + parse + symbols" + ), } Ok(()) } -- cgit v1.2.3