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
);
30 printf("key: %s\nexpires: %llu\n", argv
[optind
], (unsigned long long)opt_expire
);
31 rc
= memcached_delete(memc
, argv
[optind
], strlen(argv
[optind
]), opt_expire
);
33 if (rc
!= MEMCACHED_SUCCESS
)
35 fprintf(stderr
, "memrm: %s: memcache error %s\n",
36 argv
[optind
], memcached_strerror(memc
, rc
));
42 memcached_deinit(memc
);
50 void options_parse(int argc
, char *argv
[])
52 static struct option long_options
[]=
54 {"version", no_argument
, NULL
, OPT_VERSION
},
55 {"help", no_argument
, NULL
, OPT_HELP
},
56 {"verbose", no_argument
, &opt_verbose
, OPT_VERBOSE
},
57 {"debug", no_argument
, &opt_verbose
, OPT_DEBUG
},
58 {"servers", required_argument
, NULL
, OPT_SERVERS
},
59 {"expire", required_argument
, NULL
, OPT_EXPIRE
},
67 option_rv
= getopt_long(argc
, argv
, "Vhvds:", long_options
, &option_index
);
68 if (option_rv
== -1) break;
73 case OPT_VERBOSE
: /* --verbose or -v */
74 opt_verbose
= OPT_VERBOSE
;
76 case OPT_DEBUG
: /* --debug or -d */
77 opt_verbose
= OPT_DEBUG
;
79 case OPT_VERSION
: /* --version or -V */
80 printf("memcache tools, memrm, v1.0\n");
83 case OPT_HELP
: /* --help or -h */
84 printf("useful help messages go here\n");
87 case OPT_SERVERS
: /* --servers or -s */
88 opt_servers
= strdup(optarg
);
90 case OPT_EXPIRE
: /* --expire */
91 opt_expire
= (time_t)strtoll(optarg
, (char **)NULL
, 10);
94 /* getopt_long already printed an error message. */