Permalink
Browse files

Working on cpplint integration

  • Loading branch information...
1 parent 8abb7ae commit 3b50787963c0793ee527dfe15dc844bbf684ea2c @bmatheny committed Jun 4, 2013
Showing with 4,068 additions and 27 deletions.
  1. +4,023 −0 rel-eng/cpplint.py
  2. +34 −20 src/cli.cpp
  3. +11 −7 src/cli.h
View
Oops, something went wrong.
View
@@ -1,9 +1,12 @@
-#include <cstdlib>
-
+/**
+ * Copyright 2013 Blake Matheny
+ */
extern "C" {
#include <getopt.h>
}
+#include <cstdlib>
+#include <string>
#include "common.h"
#include "cli.h"
@@ -22,32 +25,43 @@ static const struct option longopts[] = {
};
static const char * argp = "d:i:l:p:r:R:hvV";
-using namespace std;
+using std::cout; using std::endl;
+using std::string; using std::ostringstream;
-string Cli::help(const char * progname)
-{
+string Cli::help(const char * progname) {
ostringstream txt;
string pname = progname;
string tab = " ";
txt << "Usage: " << pname << " -i NIC [options]" << endl;
- txt << mkHelpDoc(longopts[0], "Discard keys where req/s rate is below THRESH", "THRESH");
- txt << mkHelpDoc(longopts[1], "Network interface to capture traffic on (required)", "NIC");
- txt << mkHelpDoc(longopts[2], "Network port to capture memcache traffic on (default 11211)", "PORT");
- txt << mkHelpDoc(longopts[3], "Refresh the stats display every INTERVAL ms (default 500)", "INTERVAL");
+ txt << mkHelpDoc(longopts[0],
+ "Discard keys where req/s rate is below THRESH", "THRESH");
+ txt << mkHelpDoc(longopts[1],
+ "Network interface to capture traffic on (required)", "NIC");
+ txt << mkHelpDoc(
+ longopts[2],
+ "Network port to capture memcache traffic on (default 11211)",
+ "PORT");
+ txt << mkHelpDoc(
+ longopts[3],
+ "Refresh the stats display every INTERVAL ms (default 500)",
+ "INTERVAL");
txt << mkHelpDoc(longopts[7], "Output logs to FILE", "FILE");
- txt << mkHelpDoc(longopts[8], "Output data in REPORT format (CSV or curses, default curses)", "REPORT");
+ txt << mkHelpDoc(
+ longopts[8],
+ "Output data in REPORT format (CSV or curses, default curses)",
+ "REPORT");
txt << endl;
txt << mkHelpDoc(longopts[4], "This help", "");
- txt << mkHelpDoc(longopts[5], "Increase verbosity. May be used multiple times.", "");
+ txt << mkHelpDoc(longopts[5],
+ "Increase verbosity. May be used multiple times.", "");
txt << mkHelpDoc(longopts[6], "Show program info and exit.", "");
return txt.str();
}
/**
* Parse the command line arguments, updating a config as appropriate.
*/
-void Cli::parse(int argc, char ** argv, Config * cfg)
-{
+void Cli::parse(int argc, char ** argv, Config * cfg) {
int c;
char * progname = argv[0];
while (1) {
@@ -97,30 +111,30 @@ void Cli::parse(int argc, char ** argv, Config * cfg)
}
}
-string Cli::mkHelpLead(const struct option opt, const string &key)
-{
+string Cli::mkHelpLead(const struct option opt, const string &key) {
ostringstream txt;
+ static const char c = 0;
ssize_t len = 0, alloc = 33;
char * os = NULL;
- txt << " -" << ((char)opt.val) << ", --" << opt.name;
+ txt << " -" << static_cast<char>(opt.val) << ", --" << opt.name;
if (opt.has_arg == 1) {
txt << "=" << key;
} else if (opt.has_arg == 2) {
txt << "[=" << key << "]";
}
len = txt.str().length();
alloc += len;
- os = (char*)malloc(sizeof(char)*alloc);
+ os = reinterpret_cast<char*>(malloc(sizeof(c)*alloc));
snprintf(os, alloc, "%-32s", txt.str().c_str());
return string(os);
}
-string Cli::mkHelpDoc(const struct option opt, const string &desc, const string &key)
-{
+string Cli::mkHelpDoc(const struct option opt, const string &desc,
+ const string &key) {
ostringstream txt;
string lead = mkHelpLead(opt, key);
txt << lead << desc << endl;
return txt.str();
}
-} // end namespace
+} // namespace mckeys
View
@@ -1,12 +1,16 @@
-#ifndef CLI_H
-#define CLI_H
+#ifndef SRC_CLI_H_
+#define SRC_CLI_H_
-#include "config.h"
+/**
+ * Copyright 2013 Blake Matheny
+ */
+#include <string>
namespace mckeys {
-class Cli
-{
+class Config;
+
+class Cli {
public:
static void parse(int argc, char ** argv, Config * cfg);
static std::string help(const char * progname);
@@ -19,5 +23,5 @@ class Cli
const std::string &key);
};
-} // end namespace
-#endif
+} // namespace mckeys
+#endif // SRC_CLI_H_

0 comments on commit 3b50787

Please sign in to comment.