5 #include "client_options.h"
8 static int opt_verbose
= 0;
9 static time_t opt_expire
= 0;
10 static char *opt_servers
= NULL
;
12 #define PROGRAM_NAME "memflush"
13 #define PROGRAM_DESCRIPTION "Erase all data in a server of memcached servers."
16 void options_parse(int argc
, char *argv
[]);
18 int main(int argc
, char *argv
[])
22 memcached_server_st
*servers
;
24 options_parse(argc
, argv
);
30 if ((temp
= getenv("MEMCACHED_SERVERS")))
31 opt_servers
= strdup(temp
);
36 memc
= memcached_create(NULL
);
38 servers
= memcached_servers_parse(opt_servers
);
39 memcached_server_push(memc
, servers
);
40 memcached_server_list_free(servers
);
42 rc
= memcached_flush(memc
, opt_expire
);
43 if (rc
!= MEMCACHED_SUCCESS
)
45 fprintf(stderr
, "memflush: memcache error %s\n",
46 memcached_strerror(memc
, rc
));
57 void options_parse(int argc
, char *argv
[])
59 memcached_programs_help_st help_options
[]=
64 static struct option long_options
[]=
66 {"version", no_argument
, NULL
, OPT_VERSION
},
67 {"help", no_argument
, NULL
, OPT_HELP
},
68 {"verbose", no_argument
, &opt_verbose
, OPT_VERBOSE
},
69 {"debug", no_argument
, &opt_verbose
, OPT_DEBUG
},
70 {"servers", required_argument
, NULL
, OPT_SERVERS
},
71 {"expire", required_argument
, NULL
, OPT_EXPIRE
},
79 option_rv
= getopt_long(argc
, argv
, "Vhvds:", long_options
, &option_index
);
80 if (option_rv
== -1) break;
85 case OPT_VERBOSE
: /* --verbose or -v */
86 opt_verbose
= OPT_VERBOSE
;
88 case OPT_DEBUG
: /* --debug or -d */
89 opt_verbose
= OPT_DEBUG
;
91 case OPT_VERSION
: /* --version or -V */
92 version_command(PROGRAM_NAME
);
94 case OPT_HELP
: /* --help or -h */
95 help_command(PROGRAM_NAME
, PROGRAM_DESCRIPTION
, long_options
, help_options
);
97 case OPT_SERVERS
: /* --servers or -s */
98 opt_servers
= strdup(optarg
);
100 case OPT_EXPIRE
: /* --expire */
101 opt_expire
= (time_t)strtoll(optarg
, (char **)NULL
, 10);
104 /* getopt_long already printed an error message. */