6 #include "client_options.h"
9 #define PROGRAM_NAME "memcat"
10 #define PROGRAM_DESCRIPTION "Cat a set of key values to stdout."
14 void options_parse(int argc
, char *argv
[]);
16 static int opt_verbose
= 0;
17 static int opt_displayflag
= 0;
18 static char *opt_servers
;
20 int main(int argc
, char *argv
[])
27 memcached_server_st
*servers
;
29 options_parse(argc
, argv
);
34 memc
= memcached_init(NULL
);
36 servers
= parse_opt_servers(opt_servers
);
37 memcached_server_push(memc
, servers
);
38 memcached_server_list_free(servers
);
42 string
= memcached_get(memc
, argv
[optind
], strlen(argv
[optind
]),
43 &string_length
, &flags
, &rc
);
44 if (rc
== MEMCACHED_SUCCESS
)
49 printf("key: %s\nflags: ", argv
[optind
]);
50 printf("%x\n", flags
);
55 printf("key: %s\nflags: %x\nlength: %zu\nvalue: ",
56 argv
[optind
], flags
, string_length
);
57 printf("%.*s\n", (int)string_length
, string
);
63 fprintf(stderr
, "memcat: %s: memcache error %s\n",
64 argv
[optind
], memcached_strerror(memc
, rc
));
69 memcached_deinit(memc
);
77 void options_parse(int argc
, char *argv
[])
82 memcached_programs_help_st help_options
[]=
87 static struct option long_options
[]=
89 {"version", no_argument
, NULL
, OPT_VERSION
},
90 {"help", no_argument
, NULL
, OPT_HELP
},
91 {"verbose", no_argument
, &opt_verbose
, OPT_VERBOSE
},
92 {"debug", no_argument
, &opt_verbose
, OPT_DEBUG
},
93 {"servers", required_argument
, NULL
, OPT_SERVERS
},
94 {"flag", no_argument
, &opt_displayflag
, OPT_FLAG
},
100 option_rv
= getopt_long(argc
, argv
, "Vhvds:", long_options
, &option_index
);
101 if (option_rv
== -1) break;
106 case OPT_VERBOSE
: /* --verbose or -v */
107 opt_verbose
= OPT_VERBOSE
;
109 case OPT_DEBUG
: /* --debug or -d */
110 opt_verbose
= OPT_DEBUG
;
112 case OPT_VERSION
: /* --version or -V */
113 version_command(PROGRAM_NAME
);
115 case OPT_HELP
: /* --help or -h */
116 help_command(PROGRAM_NAME
, PROGRAM_DESCRIPTION
, long_options
, help_options
);
118 case OPT_SERVERS
: /* --servers or -s */
119 opt_servers
= strdup(optarg
);
122 /* getopt_long already printed an error message. */