95e3e98612cd6e4ec0c8c5a4a2e69d9ec934f19b
5 #include "client_options.h"
8 static int opt_verbose
= 0;
9 static time_t opt_expire
= 0;
10 static char *opt_servers
= NULL
;
13 void options_parse(int argc
, char *argv
[]);
15 int main(int argc
, char *argv
[])
20 options_parse(argc
, argv
);
22 memc
= memcached_init(NULL
);
25 parse_opt_servers(memc
, opt_servers
);
27 rc
= memcached_flush(memc
, opt_expire
);
28 if (rc
!= MEMCACHED_SUCCESS
)
30 fprintf(stderr
, "memflush: memcache error %s\n",
31 memcached_strerror(memc
, rc
));
34 memcached_deinit(memc
);
42 void options_parse(int argc
, char *argv
[])
44 static struct option long_options
[]=
46 {"version", no_argument
, NULL
, OPT_VERSION
},
47 {"help", no_argument
, NULL
, OPT_HELP
},
48 {"verbose", no_argument
, &opt_verbose
, OPT_VERBOSE
},
49 {"debug", no_argument
, &opt_verbose
, OPT_DEBUG
},
50 {"servers", required_argument
, NULL
, OPT_SERVERS
},
51 {"expire", required_argument
, NULL
, OPT_EXPIRE
},
59 option_rv
= getopt_long(argc
, argv
, "Vhvds:", long_options
, &option_index
);
60 if (option_rv
== -1) break;
65 case OPT_VERBOSE
: /* --verbose or -v */
66 opt_verbose
= OPT_VERBOSE
;
68 case OPT_DEBUG
: /* --debug or -d */
69 opt_verbose
= OPT_DEBUG
;
71 case OPT_VERSION
: /* --version or -V */
72 printf("memcache tools, memflush, v1.0\n");
75 case OPT_HELP
: /* --help or -h */
76 printf("useful help messages go here\n");
79 case OPT_SERVERS
: /* --servers or -s */
80 opt_servers
= strdup(optarg
);
82 case OPT_EXPIRE
: /* --expire */
83 opt_expire
= (time_t)strtoll(optarg
, (char **)NULL
, 10);
86 /* getopt_long already printed an error message. */