diff options
author | Jack Lloyd <[email protected]> | 2015-12-20 13:51:28 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2015-12-20 13:51:28 -0500 |
commit | 22d05ebfdbb409530fb20133cf150fb4c419faac (patch) | |
tree | 33498ae9e833f11cf2c27d15cbfe2ff502143ccd /src/cli | |
parent | 1752f0d522eef9a4a703fccf702b4b026c1c1d01 (diff) |
Add --data-dir option to test command
Understand using '-' on the command line to mean stdin
Fix last few unit tests that wanted to write to the filesystem; removes
outdata directory.
Diffstat (limited to 'src/cli')
-rw-r--r-- | src/cli/cli.h | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/cli/cli.h b/src/cli/cli.h index d079afbc5..fdc83e97b 100644 --- a/src/cli/cli.h +++ b/src/cli/cli.h @@ -157,6 +157,7 @@ class Command } } + bool seen_stdin_flag = false; size_t arg_i = 0; for(auto&& arg : m_spec_args) { @@ -171,6 +172,13 @@ class Command m_user_args.insert(std::make_pair(arg, args[arg_i])); + if(args[arg_i] == "-") + { + if(seen_stdin_flag) + throw CLI_Usage_Error("Cannot specifiy '-' (stdin) more than once"); + seen_stdin_flag = true; + } + ++arg_i; } @@ -235,6 +243,8 @@ class Command return "Usage: " + m_spec; } + const std::string& cmd_spec() const { return m_spec; } + std::string cmd_name() const { return m_spec.substr(0, m_spec.find(' ')); @@ -403,9 +413,21 @@ class Command std::function<void (uint8_t[], size_t)> consumer_fn, size_t buf_size = 0) const { - // Any need to support non-binary files here? - std::ifstream in(input_file, std::ios::binary); + if(input_file == "-") + { + do_read_file(std::cin, consumer_fn, buf_size); + } + else + { + std::ifstream in(input_file, std::ios::binary); + do_read_file(in, consumer_fn, buf_size); + } + } + void do_read_file(std::istream& in, + std::function<void (uint8_t[], size_t)> consumer_fn, + size_t buf_size = 0) const + { // Avoid an infinite loop on --buf-size=0 std::vector<uint8_t> buf(buf_size == 0 ? 4096 : buf_size); |