aboutsummaryrefslogtreecommitdiff
path: root/build2/b.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-01-30 15:44:43 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-01-30 15:44:43 +0200
commit79b1374a7fbf5476e80538215b3eb26fbc5de08c (patch)
treefbfdd0ce317cd521d9c683d14580e39478995a15 /build2/b.cxx
parent13b9b8fbaa8c3fd3a2e459039f8f6f5b4d3560ee (diff)
Use pager to show usage
Diffstat (limited to 'build2/b.cxx')
-rw-r--r--build2/b.cxx35
1 files changed, 24 insertions, 11 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 <iostream>
#include <system_error>
+#include <butl/pager>
#include <butl/filesystem>
#include <build2/version>
@@ -41,6 +42,7 @@
#include <build2/b-options>
+using namespace butl;
using namespace std;
#include <build2/config/module>
@@ -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 ();