Skip to content

Commit

Permalink
Merge branch 'krypt-n-feature/stdin'
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoupey committed Feb 23, 2021
2 parents 02a3915 + 072bcc6 commit 313e1f9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Changed

- Formatting script updated to use version 10 of clang-format (#452)
- vroom will now read json input from stdin if no other input is specified (#457)

### Fixed

Expand Down
25 changes: 14 additions & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void display_usage() {
usage += "Version: " + vroom::get_version() + "\n";
usage += "Usage:\n\tvroom [OPTION]... \"INPUT\"";
usage += "\n\tvroom [OPTION]... -i FILE\n";
usage += "\tvroom [OPTION]...\n";
usage += "Options:\n";
usage += "\t-a PROFILE:HOST (=" + vroom::DEFAULT_PROFILE +
":0.0.0.0)\t routing server\n";
Expand Down Expand Up @@ -154,19 +155,21 @@ int main(int argc, char** argv) {
cl_args.servers.emplace(vroom::DEFAULT_PROFILE, vroom::Server());
}

if (cl_args.input_file.empty()) {
// Getting input from command-line.
if (argc == optind) {
// Missing argument!
display_usage();
}
cl_args.input = argv[optind];
} else {
// Getting input from provided file.
std::ifstream ifs(cl_args.input_file);
// Read input problem
if (optind == argc) {
std::stringstream buffer;
buffer << ifs.rdbuf();
if (cl_args.input_file.empty()) {
// Getting input from stdin.
buffer << std::cin.rdbuf();
} else {
// Getting input from provided file.
std::ifstream ifs(cl_args.input_file);
buffer << ifs.rdbuf();
}
cl_args.input = buffer.str();
} else {
// Getting input from command-line.
cl_args.input = argv[optind];
}

try {
Expand Down

0 comments on commit 313e1f9

Please # to comment.