summaryrefslogtreecommitdiffstats
path: root/bdep/help.cxx
blob: 0ba22b304de0b6339d7b9a3e024feed1cae760d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// file      : bdep/help.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2018 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>

// Help topics.
//
#include <bdep/projects-configs.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 if (t == "projects-configs")
        usage = &print_bdep_projects_configs_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 ();
  }
}