aboutsummaryrefslogtreecommitdiff
path: root/bpkg/help.cxx
blob: 89ce93ff28e1f3ccde3990c598e6874b938927db (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// 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 help [<command>|<topic>]" << 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 summarized below. Note that they can also "
      "be specified" << endl
      << "as part of the command-specific options." << endl
      << endl;

    common_options::print_short_usage (o);
    o << endl;

    o << ""<< endl;
  }

  void
  help (const help_options&, const string& t, void (*usage) (std::ostream&))
  {
    ostream& o (cout);

    if (usage != nullptr)    // Command.
    {
      usage (o);

      o << endl
        << "The common options are summarized below. For details, see the " <<
        "'options' help" << endl
        << "topic." << endl
        << endl;

      common_options::print_short_usage (o);
    }
    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";
  }
}