From: Sage Weil Date: Fri, 27 Feb 2009 18:23:21 +0000 (-0800) Subject: cconf: ability to list section names X-Git-Tag: v0.7~120 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6b5c13b65aed4683446b5bd6a12ca4effa295948;p=ceph.git cconf: ability to list section names './cconf -c ceph.conf -l foo' will list all section names that begin with 'foo'. --- diff --git a/src/cconf.cc b/src/cconf.cc index ef6f1e77d9d..5b98b9c237e 100644 --- a/src/cconf.cc +++ b/src/cconf.cc @@ -14,7 +14,7 @@ using namespace std; void usage() { - cerr << "usage: cconf [--conf_file filename] [-s]
[[-s section] ... ] [default]" << std::endl; + cerr << "usage: cconf [--conf_file filename] [-l|--list_sections prefix] [-s
] [[-s section] ... ] [default]" << std::endl; exit(1); } @@ -22,6 +22,7 @@ int main(int argc, const char **argv) { const char *fname = g_conf.conf_file; const char *key = NULL, *defval = NULL; + const char *list_sections = 0; char *val; int param = 0; vector args; @@ -39,6 +40,12 @@ int main(int argc, const char **argv) fname = args[++i]; else usage(); + } else if (strcmp(args[i], "-l") == 0 || + strcmp(args[i], "--list_sections") == 0) { + if (i < args.size() - 1) + list_sections = args[++i]; + else + usage(); } else if (strcmp(args[i], "-s") == 0) { if (param == 0) param++; @@ -62,12 +69,22 @@ int main(int argc, const char **argv) } } - if ((param < 1) || (param > 3)) + if (!list_sections && (param < 1 || param > 3)) usage(); ConfFile cf(fname); parse_config_file(&cf, true); + if (list_sections) { + for (std::list::const_iterator p = cf.get_section_list().begin(); + p != cf.get_section_list().end(); + p++) { + if (strncmp(list_sections, (*p)->get_name().c_str(), strlen(list_sections)) == 0) + cout << (*p)->get_name() << std::endl; + } + return 0; + } + for (unsigned i=0; i SectionMap; @@ -84,6 +86,8 @@ public: ConfFile(const char *fname) : filename(strdup(fname)), auto_update(false) {} ~ConfFile(); + const SectionList& get_section_list() { return sections_list; } + int parse(); int read(const char *section, const char *var, int *val, int def_val); int read(const char *section, const char *var, unsigned int *val, unsigned int def_val);