From 5f58b2e963b21e5522c234d868bcb52cbdff5adb Mon Sep 17 00:00:00 2001 From: Ein Anderssson Date: Wed, 23 Aug 2023 21:37:13 +0200 Subject: [PATCH 1/2] new flag for csv output --- .gitignore | 6 ++++++ README.md | 4 ++++ src/cli/cliclient.cpp | 16 +++++++++------- src/cli/cliclient.h | 1 + src/cli/utils.cpp | 4 ++++ 5 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3d4e413 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.d +*.o +src/cli/cli + + # VSCode +.vscode \ No newline at end of file diff --git a/README.md b/README.md index d2e4dec..4b039cc 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/cli/cliclient.cpp b/src/cli/cliclient.cpp index d05666d..79d4b37 100644 --- a/src/cli/cliclient.cpp +++ b/src/cli/cliclient.cpp @@ -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()) { @@ -166,6 +167,7 @@ void CliClient::newEventFromAgent(std::deque &return_msgs, std::string tst = arg_obj["task"].string_value(); if (tst == "global") { if (out_quiet) { + // Enable output: out->clear(std::istream::goodbit); @@ -173,17 +175,17 @@ void CliClient::newEventFromAgent(std::deque &return_msgs, *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") { diff --git a/src/cli/cliclient.h b/src/cli/cliclient.h index 8b920fa..94614ff 100644 --- a/src/cli/cliclient.h +++ b/src/cli/cliclient.h @@ -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: diff --git a/src/cli/utils.cpp b/src/cli/utils.cpp index de17099..1516494 100644 --- a/src/cli/utils.cpp +++ b/src/cli/utils.cpp @@ -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) @@ -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; From 2e575835aa01c9ff08e29f95de867529a44790a2 Mon Sep 17 00:00:00 2001 From: Ein Andersson <1490934+einand@users.noreply.github.com> Date: Tue, 16 Apr 2024 00:26:14 +0200 Subject: [PATCH 2/2] Update cliclient.h --- src/cli/cliclient.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cli/cliclient.h b/src/cli/cliclient.h index e7acf01..6e6cfb9 100644 --- a/src/cli/cliclient.h +++ b/src/cli/cliclient.h @@ -37,7 +37,6 @@ class CliClient : public Logger, public SynchronousClient { void do_output(const char *msg, bool final = false); 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;