Inline help

This commit is contained in:
Aleksey Kladov 2020-02-17 17:14:55 +01:00
parent 0353e1c6f4
commit d5371b5dec
2 changed files with 96 additions and 82 deletions

View file

@ -1,75 +0,0 @@
//! FIXME: write short doc here
pub const GLOBAL_HELP: &str = "ra-cli
USAGE:
ra_cli <SUBCOMMAND>
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 <PATH:LINE:COLUMN> Compute completions at this location
--highlight <PATH> Hightlight this file
ARGS:
<PATH> 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 <ONLY>
ARGS:
<PATH>";
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";

View file

@ -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 <ONLY>
ARGS:
<PATH>"
);
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 <PATH:LINE:COLUMN> Compute completions at this location
--highlight <PATH> Hightlight this file
ARGS:
<PATH> 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<String> = 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 <SUBCOMMAND>
FLAGS:
-h, --help Prints help information
SUBCOMMANDS:
analysis-bench
analysis-stats
highlight
parse
symbols"
),
}
Ok(())
}