From 79b1374a7fbf5476e80538215b3eb26fbc5de08c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 30 Jan 2016 15:44:43 +0200 Subject: Use pager to show usage --- build2/b.cxx | 35 ++++++++++++++++++++++++----------- build2/buildfile | 2 +- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/build2/b.cxx b/build2/b.cxx index 96a480a..0cfb6d8 100644 --- a/build2/b.cxx +++ b/build2/b.cxx @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -41,6 +42,7 @@ #include +using namespace butl; using namespace std; #include @@ -63,6 +65,12 @@ main (int argc, char* argv[]) cl::argv_scanner scan (argc, argv, true); options ops (scan); + // Diagnostics verbosity. + // + verb = ops.verbose_specified () + ? ops.verbose () + : ops.v () ? 2 : ops.q () ? 0 : 1; + // Version. // if (ops.version ()) @@ -78,21 +86,26 @@ main (int argc, char* argv[]) // if (ops.help ()) { - ostream& o (cout); + try + { + pager p ("b help", + verb >= 2, + ops.pager_specified () ? &ops.pager () : nullptr, + &ops.pager_option ()); - o << "Usage: " << argv[0] << " [options] [variables] [buildspec]" << endl - << "Options:" << endl; + print_b_usage (p.stream ()); - options::print_usage (o); - return 0; + // If the pager failed, assume it has issued some diagnostics. + // + return p.wait () ? 0 : 1; + } + catch (const system_error& e) + { + error << "pager failed: " << e.what (); + return 1; + } } - // Diagnostics verbosity. - // - verb = ops.verbose_specified () - ? ops.verbose () - : ops.v () ? 2 : ops.q () ? 0 : 1; - // Initialize time conversion data that is used by localtime_r(). // tzset (); diff --git a/build2/buildfile b/build2/buildfile index 412b348..9805378 100644 --- a/build2/buildfile +++ b/build2/buildfile @@ -82,7 +82,7 @@ cli.options += -I $src_root --include-with-brackets --include-prefix build2 \ # Usage options. # cli.options += --suppress-undocumented --long-usage --ansi-color \ ---page-usage 'build2::print_$name$_' --option-length 23 +--page-usage 'build2::print_$name$_' --option-length 20 # Include generated cli files into the distribution. # -- cgit v1.1