diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2018-03-07 15:22:51 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2018-03-07 15:22:51 +0200 |
commit | 1c36adab776a900adc7325f412b1c8dd61b1a346 (patch) | |
tree | 0227b8c5697d24a862aedd59b9bfe28cc84e91b4 /bdep/help.cxx | |
parent | 2e2c3a81b47c650334f5767ddb4ebb2746ef98f1 (diff) |
Setup compilation, command line handling
Diffstat (limited to 'bdep/help.cxx')
-rw-r--r-- | bdep/help.cxx | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/bdep/help.cxx b/bdep/help.cxx new file mode 100644 index 0000000..ec2c4c2 --- /dev/null +++ b/bdep/help.cxx @@ -0,0 +1,59 @@ +// file : bdep/help.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include <bdep/help.hxx> + +#include <libbutl/pager.mxx> + +#include <bdep/diagnostics.hxx> +#include <bdep/bdep-options.hxx> + +using namespace std; +using namespace butl; + +namespace bdep +{ + int + help (const help_options& o, const string& t, usage_function* usage) + { + if (usage == nullptr) // Not a command. + { + if (t.empty ()) // General help. + usage = &print_bdep_usage; + // + // Help topics. + // + else if (t == "common-options") + usage = &print_bdep_common_options_long_usage; + else + fail << "unknown bdep command/help topic '" << t << "'" << + info << "run 'bdep help' for more information"; + } + + try + { + pager p ("bdep " + (t.empty () ? "help" : t), + verb >= 2, + o.pager_specified () ? &o.pager () : nullptr, + &o.pager_option ()); + + usage (p.stream (), cli::usage_para::none); + + // If the pager failed, assume it has issued some diagnostics. + // + return p.wait () ? 0 : 1; + } + // Catch io_error as std::system_error together with the pager-specific + // exceptions. + // + catch (const system_error& e) + { + error << "pager failed: " << e; + + // Fall through. + } + + throw failed (); + } +} |