aboutsummaryrefslogtreecommitdiff
path: root/bpkg/help.cxx
blob: e4cb963c8c3cee5db417f0e0a6b4d86ae9b67e44 (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
66
67
// 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>

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;
  }

  void
  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";
  }
}