Skip to content

Commit 922e14f

Browse files
committed
memcat: make file argutent to --file optional and default to <key>
1 parent b5e8dee commit 922e14f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/bin/memcat.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ memcached_return_t memcat(const client_options &opt, memcached_st *memc, const c
4545
if (verbose) {
4646
*ref << "value: ";
4747
}
48-
48+
4949
ref->write(val, len);
5050

5151
if (verbose || !opt.isset("file")) {
@@ -68,7 +68,8 @@ int main(int argc, char *argv[]) {
6868
opt.add(def);
6969
}
7070
opt.add("flags", 'F', no_argument, "Display key flags, too.");
71-
opt.add("file", 'f', required_argument, "Output to file instead of standard output.");
71+
opt.add("file", 'f', optional_argument, "Output to file instead of standard output."
72+
"\n\t\t# NOTE: defaults to <key> if no argument was provided.");
7273

7374
char **argp = nullptr;
7475
if (!opt.parse(argc, argv, &argp)) {
@@ -99,8 +100,9 @@ int main(int argc, char *argv[]) {
99100
for (auto arg = argp; *arg; ++arg) {
100101
auto key = *arg;
101102
if (*key) {
103+
char *file = opt.isset("file") ? (opt.argof("file") ?: key) : nullptr;
102104
std::ofstream fstream{};
103-
std::ostream *ostream = check_ostream(opt, opt.argof("file"), fstream);
105+
std::ostream *ostream = check_ostream(opt, file, fstream);
104106

105107
if (!check_return(opt, memc, key, memcat(opt, &memc, key, ostream))) {
106108
exit_code = EXIT_FAILURE;

0 commit comments

Comments
 (0)