]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cconf: ability to list section names
authorSage Weil <sage@newdream.net>
Fri, 27 Feb 2009 18:23:21 +0000 (10:23 -0800)
committerSage Weil <sage@newdream.net>
Fri, 27 Feb 2009 18:23:21 +0000 (10:23 -0800)
'./cconf -c ceph.conf -l foo' will list all section names that begin with
'foo'.

src/cconf.cc
src/common/ConfUtils.h

index ef6f1e77d9d5b2fdc925e5ec335668750ba1edd4..5b98b9c237ebf66d3e204a1ea053b4fcea030335 100644 (file)
@@ -14,7 +14,7 @@ using namespace std;
 
 void usage() 
 {
-  cerr << "usage: cconf [--conf_file filename] [-s] <section> [[-s section] ... ] <key> [default]" << std::endl;
+  cerr << "usage: cconf [--conf_file filename] [-l|--list_sections prefix] [-s <section>] [[-s section] ... ] <key> [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<const char*> 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<ConfSection*>::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<sections.size(); i++) {
     cf.read(sections[i], key, (char **)&val, NULL);
 
index 1f1d8a30afc4667d6bdd099f308b24fcd8f1758c..f37c71c43171b1b2d7ebb5bfcf87da89c7302dc2 100644 (file)
@@ -55,6 +55,8 @@ class ConfSection
 public:
        ~ConfSection();
        ConfSection(std::string sec_name) : name(sec_name) { }
+
+       const std::string& get_name() { return name; }
 };
 
 typedef std::map<std::string, ConfSection *> 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);