diff options
Diffstat (limited to 'src/cli/cli.h')
-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); |