]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/common/get_command_descriptions.cc
update sources to v12.1.2
[ceph.git] / ceph / src / test / common / get_command_descriptions.cc
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3/*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2013 Cloudwatt <libre.licensing@cloudwatt.com>
7 *
8 * Author: Loic Dachary <loic@dachary.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Library Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library Public License for more details.
19 *
20 */
21
22#include <stdio.h>
23#include <signal.h>
24#include "mon/Monitor.h"
25#include "common/ceph_argparse.h"
26#include "global/global_init.h"
27
28static void usage(ostream &out)
29{
30 out << "usage: get_command_descriptions [options ...]" << std::endl;
31 out << "print on stdout the result of JSON formatted options\n";
32 out << "found in mon/MonCommands.h as produced by the\n";
33 out << "Monitor.cc::get_command_descriptions function.\n";
34 out << "Designed as a helper for ceph_argparse.py unit tests.\n";
35 out << "\n";
36 out << " --all all of mon/MonCommands.h \n";
37 out << " --pull585 reproduce the bug fixed by #585\n";
38 out << "\n";
39 out << "Examples:\n";
40 out << " get_command_descriptions --all\n";
41 out << " get_command_descriptions --pull585\n";
42}
43
c07f9fc5 44static void json_print(const std::vector<MonCommand> &mon_commands)
7c673cae
FG
45{
46 bufferlist rdata;
47 Formatter *f = Formatter::create("json");
c07f9fc5 48 Monitor::format_command_descriptions(mon_commands, f, &rdata);
7c673cae
FG
49 delete f;
50 string data(rdata.c_str(), rdata.length());
51 cout << data << std::endl;
52}
53
54static void all()
55{
56#undef FLAG
57#undef COMMAND
58#undef COMMAND_WITH_FLAG
c07f9fc5 59 std::vector<MonCommand> mon_commands = {
7c673cae
FG
60#define FLAG(f) (MonCommand::FLAG_##f)
61#define COMMAND(parsesig, helptext, modulename, req_perms, avail) \
62 {parsesig, helptext, modulename, req_perms, avail, 0},
63#define COMMAND_WITH_FLAG(parsesig, helptext, modulename, req_perms, avail, flags) \
64 {parsesig, helptext, modulename, req_perms, avail, flags},
65#include <mon/MonCommands.h>
66#undef COMMAND
67#undef COMMAND_WITH_FLAG
68
7c673cae
FG
69#define COMMAND(parsesig, helptext, modulename, req_perms, avail) \
70 {parsesig, helptext, modulename, req_perms, avail, FLAG(MGR)},
71#define COMMAND_WITH_FLAG(parsesig, helptext, modulename, req_perms, avail, flags) \
72 {parsesig, helptext, modulename, req_perms, avail, flags | FLAG(MGR)},
73#include <mgr/MgrCommands.h>
74 #undef COMMAND
75#undef COMMAND_WITH_FLAG
76 };
77
c07f9fc5 78 json_print(mon_commands);
7c673cae
FG
79}
80
81// syntax error https://github.com/ceph/ceph/pull/585
82static void pull585()
83{
c07f9fc5 84 std::vector<MonCommand> mon_commands = {
7c673cae
FG
85 { "osd pool create "
86 "name=pool,type=CephPoolname "
87 "name=pg_num,type=CephInt,range=0 "
88 "name=pgp_num,type=CephInt,range=0,req=false" // !!! missing trailing space
89 "name=properties,type=CephString,n=N,req=false,goodchars=[A-Za-z0-9-_.=]",
90 "create pool", "osd", "rw", "cli,rest" }
91 };
92
c07f9fc5 93 json_print(mon_commands);
7c673cae
FG
94}
95
96int main(int argc, char **argv) {
97 vector<const char*> args;
98 argv_to_vec(argc, (const char **)argv, args);
99
100 auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
101 CODE_ENVIRONMENT_UTILITY, 0);
102 common_init_finish(g_ceph_context);
103
104 if (args.empty()) {
105 usage(cerr);
106 exit(1);
107 }
108 for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ++i) {
109 string err;
110
111 if (*i == string("help") || *i == string("-h") || *i == string("--help")) {
112 usage(cout);
113 exit(0);
114 } else if (*i == string("--all")) {
115 all();
116 } else if (*i == string("--pull585")) {
117 pull585();
118 }
119 }
120}
121
122/*
123 * Local Variables:
124 * compile-command: "cd ../.. ;
125 * make get_command_descriptions &&
126 * ./get_command_descriptions --all --pull585"
127 * End:
128 */
129