]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: --list-checks now lists options associated with check passes
authorPetr Machata <pmachata@redhat.com>
Fri, 24 Sep 2010 16:41:40 +0000 (18:41 +0200)
committerPetr Machata <pmachata@redhat.com>
Fri, 24 Sep 2010 16:41:40 +0000 (18:41 +0200)
dwarflint/dwarflint.cc
dwarflint/option.cc
dwarflint/option.hh

index 2a56a370457e757b14b0839c6f6b7c97b90e6108..6d01f7e028c3a28e56e9e07f2736c27e189500ff 100644 (file)
@@ -163,6 +163,16 @@ dwarflint::check_registrar::list_checks () const
          char const *desc = cd.description ();
          if (desc != NULL)
            std::cout << desc;
+
+         options const &opts = cd.opts ();
+         if (!opts.empty ())
+           {
+             std::cout << "recognized options:" << std::endl;
+             for (options::const_iterator ot = opts.begin ();
+                  ot != opts.end (); ++ot)
+               std::cout << "  " << ot->second->format () << std::endl;
+           }
+
          std::cout << std::endl;
        }
     }
index 99277270e94bfffacfb6c2d0a299919980887f24..5312a7248a4b045212ce5bde633da9b2feb9561d 100644 (file)
@@ -209,4 +209,45 @@ option_common::option_common (char const *description,
   , _m_seen (false)
 {}
 
+std::string
+option_common::format () const
+{
+  std::string ret;
+  bool has_short = _m_opt.key < 127;
+  if (has_short)
+    {
+      char buf[3] = {};
+      std::sprintf (buf, "-%c", _m_opt.key);
+      std::string xxx (buf);
+      ret += buf;
+    }
+
+  if (_m_opt.name != NULL)
+    {
+      if (has_short)
+       ret += ", ";
+      ret += "--";
+      ret += _m_opt.name;
+    }
+
+  if (_m_opt.arg != NULL)
+    {
+      bool optional = !!(_m_opt.flags & OPTION_ARG_OPTIONAL);
+      if (optional)
+       ret += '[';
+      ret += '=';
+      ret += _m_opt.arg;
+      if (optional)
+       ret += ']';
+    }
+
+  if (_m_opt.doc != NULL)
+    {
+      ret += "\t";
+      ret += _m_opt.doc;
+    }
+
+  return ret;
+}
+
 options global_opts;
index 6bde308c3eccb6dab8cc39ec24044972228fd67d..15a9bf46365ba507034806123c49fa3a1b1c562c 100644 (file)
@@ -48,10 +48,10 @@ public:
   option_i const *getopt (int key) const;
   argp build_argp (bool toplev = false) const;
   void add (option_i *opt);
-  bool empty () const
-  {
-    return std::map<int, option_i *>::empty ();
-  }
+  using std::map<int, option_i *>::empty;
+  using std::map<int, option_i *>::begin;
+  using std::map<int, option_i *>::end;
+  using std::map<int, option_i *>::const_iterator;
 };
 
 // Wrapper of argp parsing.  While in general argp does a decent job,
@@ -97,6 +97,7 @@ public:
   virtual argp_option const &build_option () const = 0;
   virtual error_t parse_opt (char *arg, argp_state *state) = 0;
   virtual int key () const = 0;
+  virtual std::string format () const = 0;
   virtual ~option_i () {}
 };
 
@@ -131,6 +132,8 @@ public:
   {
     return _m_opt.key;
   }
+
+  std::string format () const;
 };
 
 template<class arg_type>