summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-02-10 18:56:29 +0100
committerGitHub <noreply@github.com>2018-02-10 18:56:29 +0100
commitfaafe6e994eee23f9b42d81bb33d3cb4985430f9 (patch)
tree1a4ae54e950c133a64c4a1963074a6b586c8c093 /bin
parent3342a0858741736249e40bc19ac071b2ec367106 (diff)
parentc17b256dfdd852301b3fd18ef16adef60f027d26 (diff)
Merge pull request #1265 from matthiasbeyer/imag/help
Add subcommand "help"
Diffstat (limited to 'bin')
-rw-r--r--bin/core/imag/src/main.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/bin/core/imag/src/main.rs b/bin/core/imag/src/main.rs
index b569b46d..8bc6cef3 100644
--- a/bin/core/imag/src/main.rs
+++ b/bin/core/imag/src/main.rs
@@ -121,7 +121,7 @@ fn main() {
let about = "imag - the PIM suite for the commandline";
let commands = get_commands();
let helptext = help_text(commands.clone());
- let app = Runtime::get_default_cli_builder(appname, version, about)
+ let mut app = Runtime::get_default_cli_builder(appname, version, about)
.settings(&[AppSettings::AllowExternalSubcommands, AppSettings::ArgRequiredElseHelp])
.arg(Arg::with_name("version")
.long("version")
@@ -137,6 +137,23 @@ fn main() {
.help("Get the versions of the imag commands"))
.subcommand(SubCommand::with_name("help").help("Show help"))
.after_help(helptext.as_str());
+
+ let long_help = {
+ let mut v = vec![];
+ if let Err(e) = app.write_long_help(&mut v) {
+ eprintln!("Error: {:?}", e);
+ exit(1);
+ }
+ String::from_utf8(v).unwrap_or_else(|_| { eprintln!("UTF8 Error"); exit(1) })
+ };
+ {
+ let print_help = app.clone().get_matches().subcommand_name().map(|h| h == "help").unwrap_or(false);
+ if print_help {
+ println!("{}", long_help);
+ exit(0)
+ }
+ }
+
let rt = Runtime::new(app)
.unwrap_or_else(|e| {
println!("Runtime couldn't be setup. Exiting");