Add support for -h and --verbose
This commit is contained in:
parent
1696f669af
commit
6988b0d082
@ -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] <config_path>\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<std::string> &cmd, const std::optional<fs::path> &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<std::string> 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<argc; i++) {
|
||||
std::string arg=argv[i];
|
||||
if(arg == "--help" || arg == "-h") {
|
||||
print_help(prog_name);
|
||||
return 0;
|
||||
}
|
||||
if(arg == "--verbose" || arg == "-v") {
|
||||
verbose = true;
|
||||
// Remove the verbose flag from argc and argv for further processing
|
||||
// Shift the arguments left
|
||||
for(int j=i; j<argc-1; j++) {
|
||||
argv[j] = argv[j+1];
|
||||
}
|
||||
argc--;
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
log_info("Script started.");
|
||||
fs::create_directories(LOG_DIR);
|
||||
log_info("Ensured log directory exists: " + LOG_DIR);
|
||||
@ -367,6 +404,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
if(config_path.empty()) {
|
||||
log_error("No config file specified.");
|
||||
print_help(prog_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user