Skip to content

Commit

Permalink
Merge pull request #1 from einand/add_csv_flag
Browse files Browse the repository at this point in the history
new flag for csv output
  • Loading branch information
einand committed Aug 23, 2023
2 parents 3180567 + 5f58b2e commit e29f504
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.d
*.o
src/cli/cli

# VSCode
.vscode
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
The `src` directory contains the source code to the command line version of
Bredbandskollen CLI, a bandwidth measurement tool.

# Changes from dotse
- CVS output


# How to build Bredbandskollen's CLI client

Note: Pre-compiled binaries for the most common platforms can be downloaded from
Expand Down
16 changes: 9 additions & 7 deletions src/cli/cliclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ CliClient::CliClient(const TaskConfig &config) :
#else
out_is_tty = isatty(fileno(stdout));
#endif
limiter = the_config.value("limiter");
out_quiet = (the_config.value("quiet") == "1" ||
the_config.value("logfile") == "-");
if (!the_config.value("out").empty()) {
Expand Down Expand Up @@ -166,24 +167,25 @@ void CliClient::newEventFromAgent(std::deque<std::string> &return_msgs,
std::string tst = arg_obj["task"].string_value();
if (tst == "global") {
if (out_quiet) {

// Enable output:
out->clear(std::istream::goodbit);

if (the_config.value("quiet") != "1")
*out << "\n\nRESULT: ";

std::string measurement_id = arg_obj["MeasurementID"].string_value();
*out << measurement_id << ' '
<< report.download << ' '
<< report.upload << ' '
<< report.latency << ' '
<< report.measurement_server << ' '
<< report.isp << ' '
*out << measurement_id << limiter
<< report.download << limiter
<< report.upload << limiter
<< report.latency << limiter
<< report.measurement_server << limiter
<< report.isp << limiter
<< report.ticket;
if (report.rating.empty())
*out << std::endl;
else
*out << ' ' << report.rating << std::endl;
*out << limiter << report.rating << std::endl;
}
return_msgs.push_back(BridgeTask::msgToAgent("quit"));
} else if (tst == "latency") {
Expand Down
1 change: 1 addition & 0 deletions src/cli/cliclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class CliClient : public Logger, public SynchronousClient {
void do_output(double value, const char *msg, bool final = false);
std::ostream *out;
bool out_is_tty, out_quiet;
std::string limiter = " ";
std::ostringstream current_line;
std::string current_header;
// Set to true during upload and download:
Expand Down
4 changes: 4 additions & 0 deletions src/cli/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ bool parseArgs(int argc, char *argv[],
return false;
} else if (arg == "--quiet") {
client_cfg.set("quiet", "1");
} else if (arg == "--csv") {
client_cfg.set("quiet", "1");
client_cfg.set("limiter", ",");
} else if (arg == "--local") {
mode = (mode == CliMode::NONE) ? CliMode::LOCAL : CliMode::IN_ERROR;
#if defined(RUN_SERVER)
Expand Down Expand Up @@ -217,6 +220,7 @@ bool parseArgs(int argc, char *argv[],
<< "\nCommand line interface:\n"
<< " --quiet Write a single line of output\n"
<< " --out=FILENAME Append output to FILENAME instead of stdout\n"
<< " --csv Write a single line as comma separated\n"
#endif
<< std::endl;
return false;
Expand Down

0 comments on commit e29f504

Please sign in to comment.