6 #include "client_options.h"
9 static int opt_verbose
= 0;
10 static time_t opt_expire
= 0;
11 static char *opt_servers
= NULL
;
13 #define PROGRAM_NAME "memflush"
14 #define PROGRAM_DESCRIPTION "Erase all data in a server of memcached servers."
17 void options_parse(int argc
, char *argv
[]);
19 int main(int argc
, char *argv
[])
23 memcached_server_st
*servers
;
25 options_parse(argc
, argv
);
31 if ((temp
= getenv("MEMCACHED_SERVERS")))
32 opt_servers
= strdup(temp
);
37 memc
= memcached_create(NULL
);
39 servers
= memcached_servers_parse(opt_servers
);
40 memcached_server_push(memc
, servers
);
41 memcached_server_list_free(servers
);
43 rc
= memcached_flush(memc
, opt_expire
);
44 if (rc
!= MEMCACHED_SUCCESS
)
46 fprintf(stderr
, "memflush: memcache error %s",
47 memcached_strerror(memc
, rc
));
48 if (memc
->cached_errno
)
49 fprintf(stderr
, " system error %s", strerror(memc
->cached_errno
));
50 fprintf(stderr
, "\n");
61 void options_parse(int argc
, char *argv
[])
63 memcached_programs_help_st help_options
[]=
68 static struct option long_options
[]=
70 {"version", no_argument
, NULL
, OPT_VERSION
},
71 {"help", no_argument
, NULL
, OPT_HELP
},
72 {"verbose", no_argument
, &opt_verbose
, OPT_VERBOSE
},
73 {"debug", no_argument
, &opt_verbose
, OPT_DEBUG
},
74 {"servers", required_argument
, NULL
, OPT_SERVERS
},
75 {"expire", required_argument
, NULL
, OPT_EXPIRE
},
83 option_rv
= getopt_long(argc
, argv
, "Vhvds:", long_options
, &option_index
);
84 if (option_rv
== -1) break;
89 case OPT_VERBOSE
: /* --verbose or -v */
90 opt_verbose
= OPT_VERBOSE
;
92 case OPT_DEBUG
: /* --debug or -d */
93 opt_verbose
= OPT_DEBUG
;
95 case OPT_VERSION
: /* --version or -V */
96 version_command(PROGRAM_NAME
);
98 case OPT_HELP
: /* --help or -h */
99 help_command(PROGRAM_NAME
, PROGRAM_DESCRIPTION
, long_options
, help_options
);
101 case OPT_SERVERS
: /* --servers or -s */
102 opt_servers
= strdup(optarg
);
104 case OPT_EXPIRE
: /* --expire */
105 opt_expire
= (time_t)strtoll(optarg
, (char **)NULL
, 10);
108 /* getopt_long already printed an error message. */