1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2013 Cloudwatt <libre.licensing@cloudwatt.com>
8 * Author: Loic Dachary <loic@dachary.org>
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)
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.
24 #include "mon/Monitor.h"
25 #include "common/ceph_argparse.h"
26 #include "global/global_init.h"
28 static void usage(ostream
&out
)
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";
36 out
<< " --all all of mon/MonCommands.h \n";
37 out
<< " --pull585 reproduce the bug fixed by #585\n";
40 out
<< " get_command_descriptions --all\n";
41 out
<< " get_command_descriptions --pull585\n";
44 static void json_print(const std::vector
<MonCommand
> &mon_commands
)
47 Formatter
*f
= Formatter::create("json");
48 Monitor::format_command_descriptions(mon_commands
, f
,
49 CEPH_FEATURES_ALL
, &rdata
);
51 string
data(rdata
.c_str(), rdata
.length());
52 cout
<< data
<< std::endl
;
59 #undef COMMAND_WITH_FLAG
60 std::vector
<MonCommand
> mon_commands
= {
61 #define FLAG(f) (MonCommand::FLAG_##f)
62 #define COMMAND(parsesig, helptext, modulename, req_perms) \
63 {parsesig, helptext, modulename, req_perms, 0},
64 #define COMMAND_WITH_FLAG(parsesig, helptext, modulename, req_perms, flags) \
65 {parsesig, helptext, modulename, req_perms, flags},
66 #include <mon/MonCommands.h>
68 #undef COMMAND_WITH_FLAG
70 #define COMMAND(parsesig, helptext, modulename, req_perms) \
71 {parsesig, helptext, modulename, req_perms, FLAG(MGR)},
72 #define COMMAND_WITH_FLAG(parsesig, helptext, modulename, req_perms, flags) \
73 {parsesig, helptext, modulename, req_perms, flags | FLAG(MGR)},
74 #include <mgr/MgrCommands.h>
76 #undef COMMAND_WITH_FLAG
79 json_print(mon_commands
);
82 // syntax error https://github.com/ceph/ceph/pull/585
85 std::vector
<MonCommand
> mon_commands
= {
87 "name=pool,type=CephPoolname "
88 "name=pg_num,type=CephInt,range=0,req=false "
89 "name=pgp_num,type=CephInt,range=0,req=false" // !!! missing trailing space
90 "name=properties,type=CephString,n=N,req=false,goodchars=[A-Za-z0-9-_.=]",
91 "create pool", "osd", "rw" }
94 json_print(mon_commands
);
97 int main(int argc
, char **argv
) {
98 vector
<const char*> args
;
99 argv_to_vec(argc
, (const char **)argv
, args
);
101 auto cct
= global_init(NULL
, args
, CEPH_ENTITY_TYPE_CLIENT
,
102 CODE_ENVIRONMENT_UTILITY
,
103 CINIT_FLAG_NO_DEFAULT_CONFIG_FILE
);
104 common_init_finish(g_ceph_context
);
110 for (std::vector
<const char*>::iterator i
= args
.begin(); i
!= args
.end(); ++i
) {
113 if (*i
== string("help") || *i
== string("-h") || *i
== string("--help")) {
116 } else if (*i
== string("--all")) {
118 } else if (*i
== string("--pull585")) {
126 * compile-command: "cd ../.. ;
127 * make get_command_descriptions &&
128 * ./get_command_descriptions --all --pull585"