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, &rdata);
50 string data(rdata.c_str(), rdata.length());
51 cout << data << std::endl;
58 #undef COMMAND_WITH_FLAG
59 std::vector<MonCommand> mon_commands = {
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>
67 #undef COMMAND_WITH_FLAG
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>
75 #undef COMMAND_WITH_FLAG
78 json_print(mon_commands);
81 // syntax error https://github.com/ceph/ceph/pull/585
84 std::vector<MonCommand> mon_commands = {
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" }
93 json_print(mon_commands);
96 int main(int argc, char **argv) {
97 vector<const char*> args;
98 argv_to_vec(argc, (const char **)argv, args);
100 auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
101 CODE_ENVIRONMENT_UTILITY, 0);
102 common_init_finish(g_ceph_context);
108 for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ++i) {
111 if (*i == string("help") || *i == string("-h") || *i == string("--help")) {
114 } else if (*i == string("--all")) {
116 } else if (*i == string("--pull585")) {
124 * compile-command: "cd ../.. ;
125 * make get_command_descriptions &&
126 * ./get_command_descriptions --all --pull585"