*
*/
+#include <iomanip>
#include <string>
#include "common/ceph_argparse.h"
using std::deque;
using std::string;
-static void usage()
+static void usage(std::ostream& out)
{
// TODO: add generic_usage once cerr/derr issues are resolved
- cerr << "Ceph configuration query tool\n\
-\n\
-USAGE\n\
-ceph-conf <flags> <action>\n\
-\n\
-ACTIONS\n\
- -L|--list-all-sections List all sections\n\
- -l|--list-sections <prefix> List sections with the given prefix\n\
- --filter-key <key> Filter section list to only include sections\n\
- with given key defined.\n\
- --filter-key-value <key>=<val> Filter section list to only include sections\n\
- with given key/value pair.\n\
- --lookup <key> Print a configuration setting to stdout.\n\
- Returns 0 (success) if the configuration setting is\n\
- found; 1 otherwise.\n\
- -r|--resolve-search search for the first file that exists and\n\
- can be opened in the resulted comma\n\
- delimited search list.\n\
- -D|--dump-all dump all variables.\n\
-\n\
-FLAGS\n\
- --name name Set type.id\n\
- [-s <section>] Add to list of sections to search\n\
- [--format plain|json|json-pretty]\n\
- dump variables in plain text, json or pretty\n\
- json\n\
-\n\
-If there is no action given, the action will default to --lookup.\n\
-\n\
-EXAMPLES\n\
-$ ceph-conf --name mon.0 -c /etc/ceph/ceph.conf 'mon addr'\n\
-Find out what the value of 'mon addr' is for monitor 0.\n\
-\n\
-$ ceph-conf -l mon\n\
-List sections beginning with 'mon'.\n\
-\n\
-RETURN CODE\n\
-Return code will be 0 on success; error code otherwise.\n\
-";
- exit(1);
+ out << R"(Ceph configuration query tool
+
+USAGE
+ceph-conf <flags> <action>
+
+ACTIONS
+ -L|--list-all-sections List all sections
+ -l|--list-sections <prefix> List sections with the given prefix
+ --filter-key <key> Filter section list to only include sections
+ with given key defined.
+ --filter-key-value <key>=<val> Filter section list to only include sections
+ with given key/value pair.
+ --lookup <key> Print a configuration setting to stdout.
+ Returns 0 (success) if the configuration setting is
+ found; 1 otherwise.
+ -r|--resolve-search search for the first file that exists and
+ can be opened in the resulted comma
+ delimited search list.
+ -D|--dump-all dump all variables.
+ --show-config-value <key> Print the corresponding ceph.conf value
+ that matches the specified key. Also searches
+ global defaults.
+
+FLAGS
+ --name name Set type.id
+ [-s <section>] Add to list of sections to search
+ [--format plain|json|json-pretty]
+ dump variables in plain text, json or pretty
+ json
+
+If there is no action given, the action will default to --lookup.
+
+EXAMPLES
+$ ceph-conf --name mon.0 -c /etc/ceph/ceph.conf 'mon addr'
+Find out what the value of 'mon addr' is for monitor 0.
+
+$ ceph-conf -l mon
+List sections beginning with 'mon'.
+
+RETURN CODE
+Return code will be 0 on success; error code otherwise.
+)";
}
static int list_sections(const std::string &prefix,
return 0;
}
cerr << "format '" << format << "' not recognized." << std::endl;
- usage();
+ usage(cerr);
return 1;
}
}
std::string dump_format;
argv_to_vec(argc, argv, args);
- vector<const char*> orig_args = args;
-
- global_pre_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_DAEMON,
- CINIT_FLAG_NO_DAEMON_ACTIONS |
- CINIT_FLAG_NO_MON_CONFIG);
- std::unique_ptr<CephContext,
- std::function<void(CephContext*)> > cct_deleter{
- g_ceph_context,
- [](CephContext *p) {p->put();}
- };
-
- g_conf().apply_changes(nullptr);
- g_conf().complain_about_parse_errors(g_ceph_context);
+ auto orig_args = args;
+ auto cct = [&args] {
+ std::map<std::string,std::string> defaults = {{"log_to_file", "false"}};
+ return global_init(&defaults, args, CEPH_ENTITY_TYPE_CLIENT,
+ CODE_ENVIRONMENT_DAEMON,
+ CINIT_FLAG_NO_DAEMON_ACTIONS |
+ CINIT_FLAG_NO_MON_CONFIG);
+ }();
// do not common_init_finish(); do not start threads; do not do any of thing
// wonky things the daemon whose conf we are examining would do (like initialize
size_t pos = val.find_first_of('=');
if (pos == string::npos) {
cerr << "expecting argument like 'key=value' for --filter-key-value (not '" << val << "')" << std::endl;
- usage();
- exit(1);
+ usage(cerr);
+ return EXIT_FAILURE;
}
string key(val, 0, pos);
string value(val, pos+1);
} else {
cerr << "unable to parse option: '" << *i << "'" << std::endl;
cerr << "args:";
- for (std::vector<const char *>::iterator ci = orig_args.begin(); ci != orig_args.end(); ++ci) {
- cerr << " '" << *ci << "'";
+ for (auto arg : orig_args) {
+ cerr << " " << quoted(arg);
}
cerr << std::endl;
- usage();
- exit(1);
+ usage(cerr);
+ return EXIT_FAILURE;
}
}
}
- g_ceph_context->_log->flush();
+ cct->_log->flush();
if (action == "help") {
- usage();
- exit(0);
+ usage(cout);
+ return EXIT_SUCCESS;
} else if (action == "list-sections") {
return list_sections(section_list_prefix, filter_key, filter_key_value);
} else if (action == "lookup") {
} else {
cerr << "You must give an action, such as --lookup or --list-all-sections." << std::endl;
cerr << "Pass --help for more help." << std::endl;
- exit(1);
+ return EXIT_FAILURE;
}
}