summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authormario <mario-krehl@gmx.de>2016-09-03 14:58:14 +0200
committerMatthias Beyer <mail@beyermatthias.de>2016-09-05 16:18:11 +0200
commit882b2ef5a75307f9988e2cb9646449bf5ea8f311 (patch)
tree2cf5642e2e4073ff9728d4215edb58b04524a1a4 /bin
parent1900d6922c0372aebdc5adce85f4de4cc4637b80 (diff)
Add help_text()
Replaces the help() functions with help_text(), which returns the help_text of imag. Use the .help() function of clap::App to overwrite the help text generated by clap Remove unneeded argument '--help', generated by clap now
Diffstat (limited to 'bin')
-rw-r--r--bin/src/main.rs33
1 files changed, 12 insertions, 21 deletions
diff --git a/bin/src/main.rs b/bin/src/main.rs
index f8e0ccc8..7076a2ea 100644
--- a/bin/src/main.rs
+++ b/bin/src/main.rs
@@ -19,8 +19,8 @@ use clap::{Arg, App, AppSettings, SubCommand};
use libimagrt::runtime::Runtime;
use libimagrt::setup::generate_runtime_setup;
-fn help(cmds: Vec<String>) {
- println!(r#"
+fn help_text(cmds: Vec<String>) -> String {
+ let text = format!(r#"
_
(_)_ __ ___ __ _ __ _
@@ -39,13 +39,8 @@ fn help(cmds: Vec<String>) {
modules can be used independently.
Available commands:
- "#);
- for cmd in cmds.iter() {
- println!("\t{}", cmd);
- }
-
- println!(r#"
+ {imagbins}
Call a command with 'imag <command> <args>'
Each command can be called with "--help" to get the respective helptext.
@@ -55,9 +50,16 @@ fn help(cmds: Vec<String>) {
imag is free software. It is released under the terms of LGPLv2.1
- (c) 2016 Matthias Beyer and contributors"#);
+ (c) 2016 Matthias Beyer and contributors"#, imagbins = cmds.into_iter()
+ .map(|cmd| format!("\t{}\n", cmd))
+ .fold(String::new(), |s, c| {
+ let s = s + c.as_str();
+ s
+ }));
+ text
}
+
fn get_commands() -> Vec<String> {
let path = env::var("PATH");
if path.is_err() {
@@ -118,14 +120,8 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.required(false)
.multiple(false)
.help("Get the versions of the imag commands"))
- .arg(Arg::with_name("help")
- .long("help")
- .short("h")
- .takes_value(false)
- .required(false)
- .multiple(false)
- .help("Show help"))
.subcommand(SubCommand::with_name("help").help("Show help"))
+ .help(help_text(get_commands()))
}
fn main() {
@@ -136,11 +132,6 @@ fn main() {
let matches = rt.cli();
debug!("matches: {:?}", matches);
- if matches.is_present("help") {
- debug!("Calling help()");
- help(get_commands());
- exit(0);
- }
if matches.is_present("version") {
debug!("Showing version");