aboutsummaryrefslogtreecommitdiff
path: root/bpkg/help.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-09-02 17:09:57 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-09-02 17:09:57 +0200
commit94c3574492b6db6ae8d5fbef717f8e6f92f1d402 (patch)
treed5cee1ec9d601fbf9da02f82b9ca8431880aea0b /bpkg/help.cxx
parent317cf86dedbd72aacc673c6257cc178e76ee77e3 (diff)
Command line options/commands/help infrastructure
Diffstat (limited to 'bpkg/help.cxx')
-rw-r--r--bpkg/help.cxx70
1 files changed, 70 insertions, 0 deletions
diff --git a/bpkg/help.cxx b/bpkg/help.cxx
new file mode 100644
index 0000000..b63adbd
--- /dev/null
+++ b/bpkg/help.cxx
@@ -0,0 +1,70 @@
+// file : bpkg/help.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <bpkg/help>
+
+#include <cassert>
+#include <iostream>
+
+#include <bpkg/types>
+#include <bpkg/diagnostics>
+
+#include <bpkg/bpkg-options>
+#include <bpkg/help-options>
+
+using namespace std;
+
+namespace bpkg
+{
+ static void
+ help ()
+ {
+ ostream& o (cout);
+
+ o << "usage: bpkg --help" << endl
+ << " bpkg --version" << endl
+ << " bpkg [<common-options>] <command> [<command-options>] " <<
+ "[<command-args>]" << endl
+ << endl;
+
+ o << "The commands are:" << endl
+ << endl;
+
+ bpkg_commands::print_short_usage (o);
+ o << endl;
+
+ o << "The help topics are:" << endl
+ << endl;
+
+ bpkg_topics::print_short_usage (o);
+ o << endl;
+
+ o << "The common options are:" << endl
+ << endl;
+
+ common_options::print_short_usage (o);
+ o << endl;
+
+ o << "The common options can also be specified as part of the command-" <<
+ "specific ones."<< endl;
+ }
+
+ int
+ help (const help_options&, const string& t, void (*usage) (std::ostream&))
+ {
+ if (usage != nullptr) // Command.
+ usage (cout);
+ else if (t.empty ()) // General help.
+ help ();
+ else if (t == "options") // Help topics.
+ {
+ common_options::print_long_usage (cout);
+ }
+ else
+ fail << "unknown bpkg command/help topic '" << t << "'" <<
+ info << "run 'bpkg help' for more information";
+
+ return 0;
+ }
+}