From 6988b0d082bebc7d9ea15029755cbf69afdd93ce Mon Sep 17 00:00:00 2001 From: Simon Quigley Date: Sun, 15 Dec 2024 02:11:15 -0600 Subject: [PATCH] Add support for -h and --verbose --- cpp/build-packages.cpp | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/cpp/build-packages.cpp b/cpp/build-packages.cpp index 126b3dd..5980744 100644 --- a/cpp/build-packages.cpp +++ b/cpp/build-packages.cpp @@ -57,12 +57,16 @@ static const std::string REAL_LINTIAN_DIR = BASE_OUTPUT_DIR + "/lintian"; static std::string urgency_level_override = "low"; static int worker_count = 5; +// Global verbosity flag +static bool verbose = false; + static std::ofstream log_file_stream; +// Logging functions static void log_all(const std::string &msg, bool is_error=false) { if (is_error) { std::cerr << msg; - } else { + } else if (verbose) { std::cout << msg; } if (log_file_stream.is_open()) { @@ -83,6 +87,18 @@ static void log_error(const std::string &msg) { log_all("[ERROR] " + msg + "\n", true); } +static void print_help(const std::string &prog_name) { + std::cout << "Usage: " << prog_name << " [OPTIONS] \n" + << "Options:\n" + << " --skip-dput Skip uploading changes with dput.\n" + << " --skip-cleanup Skip cleaning up the output directory after execution.\n" + << " --urgency-level=LEVEL Set the urgency level (default: low).\n" + << " --workers=N Set the number of worker threads (default: 5).\n" + << " --verbose, -v Enable verbose logging.\n" + << " --help, -h Display this help message.\n"; +} + +// Adjusted run_command_silent_on_success with conditional logging static void run_command_silent_on_success(const std::vector &cmd, const std::optional &cwd = std::nullopt) { log_info("Running command: " + std::accumulate(cmd.begin(), cmd.end(), std::string(), [](const std::string &a, const std::string &b) -> std::string { return a + (a.empty() ? "" : " ") + b; })); @@ -314,6 +330,27 @@ static std::vector get_exclusions(const fs::path &packaging) { } int main(int argc, char** argv) { + // Parse command-line arguments + std::string prog_name = fs::path(argv[0]).filename().string(); + for(int i=1; i