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
);
24 parse_opt_servers(memc
, opt_servers
);
27 parse_opt_servers(memc
, opt_servers
);
32 printf("key: %s\nexpires: %llu\n", argv
[optind
], (unsigned long long)opt_expire
);
33 rc
= memcached_delete(memc
, argv
[optind
], strlen(argv
[optind
]), opt_expire
);
35 if (rc
!= MEMCACHED_SUCCESS
)
37 fprintf(stderr
, "memrm: %s: memcache error %s\n",
38 argv
[optind
], memcached_strerror(memc
, rc
));
44 memcached_deinit(memc
);
52 void options_parse(int argc
, char *argv
[])
54 static struct option long_options
[]=
56 {"version", no_argument
, NULL
, OPT_VERSION
},
57 {"help", no_argument
, NULL
, OPT_HELP
},
58 {"verbose", no_argument
, &opt_verbose
, OPT_VERBOSE
},
59 {"debug", no_argument
, &opt_verbose
, OPT_DEBUG
},
60 {"servers", required_argument
, NULL
, OPT_SERVERS
},
61 {"expire", required_argument
, NULL
, OPT_EXPIRE
},
69 option_rv
= getopt_long(argc
, argv
, "Vhvds:", long_options
, &option_index
);
70 if (option_rv
== -1) break;
75 case OPT_VERBOSE
: /* --verbose or -v */
76 opt_verbose
= OPT_VERBOSE
;
78 case OPT_DEBUG
: /* --debug or -d */
79 opt_verbose
= OPT_DEBUG
;
81 case OPT_VERSION
: /* --version or -V */
82 printf("memcache tools, memrm, v1.0\n");
85 case OPT_HELP
: /* --help or -h */
86 printf("useful help messages go here\n");
89 case OPT_SERVERS
: /* --servers or -s */
90 opt_servers
= strdup(optarg
);
92 case OPT_EXPIRE
: /* --expire */
93 opt_expire
= (time_t)strtoll(optarg
, (char **)NULL
, 10);
96 /* getopt_long already printed an error message. */