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
);
35 if ((temp
= getenv("MEMCACHED_SERVERS")))
36 opt_servers
= strdup(temp
);
41 memc
= memcached_create(NULL
);
43 servers
= memcached_servers_parse(opt_servers
);
45 memcached_server_push(memc
, servers
);
46 memcached_server_list_free(servers
);
50 string
= memcached_get(memc
, argv
[optind
], strlen(argv
[optind
]),
51 &string_length
, &flags
, &rc
);
52 if (rc
== MEMCACHED_SUCCESS
)
57 printf("key: %s\nflags: ", argv
[optind
]);
58 printf("%x\n", flags
);
63 printf("key: %s\nflags: %x\nlength: %zu\nvalue: ",
64 argv
[optind
], flags
, string_length
);
65 printf("%.*s\n", (int)string_length
, string
);
69 else if (rc
!= MEMCACHED_NOTFOUND
)
71 fprintf(stderr
, "memcat: %s: memcache error %s\n",
72 argv
[optind
], memcached_strerror(memc
, rc
));
85 void options_parse(int argc
, char *argv
[])
90 memcached_programs_help_st help_options
[]=
95 static struct option long_options
[]=
97 {"version", no_argument
, NULL
, OPT_VERSION
},
98 {"help", no_argument
, NULL
, OPT_HELP
},
99 {"verbose", no_argument
, &opt_verbose
, OPT_VERBOSE
},
100 {"debug", no_argument
, &opt_verbose
, OPT_DEBUG
},
101 {"servers", required_argument
, NULL
, OPT_SERVERS
},
102 {"flag", no_argument
, &opt_displayflag
, OPT_FLAG
},
108 option_rv
= getopt_long(argc
, argv
, "Vhvds:", long_options
, &option_index
);
109 if (option_rv
== -1) break;
114 case OPT_VERBOSE
: /* --verbose or -v */
115 opt_verbose
= OPT_VERBOSE
;
117 case OPT_DEBUG
: /* --debug or -d */
118 opt_verbose
= OPT_DEBUG
;
120 case OPT_VERSION
: /* --version or -V */
121 version_command(PROGRAM_NAME
);
123 case OPT_HELP
: /* --help or -h */
124 help_command(PROGRAM_NAME
, PROGRAM_DESCRIPTION
, long_options
, help_options
);
126 case OPT_SERVERS
: /* --servers or -s */
127 opt_servers
= strdup(optarg
);
130 /* getopt_long already printed an error message. */