From 94c3574492b6db6ae8d5fbef717f8e6f92f1d402 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 2 Sep 2015 17:09:57 +0200 Subject: Command line options/commands/help infrastructure --- bpkg/help.cxx | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 bpkg/help.cxx (limited to 'bpkg/help.cxx') 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 + +#include +#include + +#include +#include + +#include +#include + +using namespace std; + +namespace bpkg +{ + static void + help () + { + ostream& o (cout); + + o << "usage: bpkg --help" << endl + << " bpkg --version" << endl + << " bpkg [] [] " << + "[]" << 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; + } +} -- cgit v1.1