From 2623bcf2b392ec652341746e59f78fdd6e0bf1f1 Mon Sep 17 00:00:00 2001 From: Chris Punches Date: Sun, 16 Mar 2025 23:16:40 -0400 Subject: [PATCH] starting the process of moving manifest mgmt to a dedicated subcommand --- modules/build/build.cpp | 3 + modules/build/include/cli_parsers.hpp | 7 ++- modules/build/include/commands.hpp | 21 +++++++ modules/build/src/checksums.cpp | 3 +- modules/build/src/cli_parsers.cpp | 5 ++ modules/build/src/commands.cpp | 82 +++++++++++++++++++++++++++ 6 files changed, 116 insertions(+), 5 deletions(-) diff --git a/modules/build/build.cpp b/modules/build/build.cpp index 97da4d2..38bfec3 100644 --- a/modules/build/build.cpp +++ b/modules/build/build.cpp @@ -91,6 +91,9 @@ extern "C" int dpm_module_execute(const char* command, int argc, char** argv) { case CMD_HELP: return cmd_help(argc, argv); + case CMD_MANIFEST: + return cmd_manifest(argc, argv); + case CMD_UNKNOWN: default: return cmd_unknown(command, argc, argv); diff --git a/modules/build/include/cli_parsers.hpp b/modules/build/include/cli_parsers.hpp index 3b5c37b..8206f13 100644 --- a/modules/build/include/cli_parsers.hpp +++ b/modules/build/include/cli_parsers.hpp @@ -12,9 +12,10 @@ * @brief Enumeration of supported commands for the build module */ enum Command { - CMD_UNKNOWN, /**< Unknown or unsupported command */ - CMD_HELP, /**< Display help information */ - CMD_STAGE /**< Stage a new DPM package */ + CMD_UNKNOWN, /**< Unknown or unsupported command */ + CMD_HELP, /**< Display help information */ + CMD_STAGE, /**< Stage a new DPM package */ + CMD_MANIFEST, /**< Regenerate a stage manifest */ }; /** diff --git a/modules/build/include/commands.hpp b/modules/build/include/commands.hpp index e84a268..717fd46 100644 --- a/modules/build/include/commands.hpp +++ b/modules/build/include/commands.hpp @@ -16,6 +16,17 @@ */ int cmd_stage(int argc, char** argv); +/** + * @brief Handler for the manifest command + * + * Generates or refreshes package manifest. + * + * @param argc Number of arguments + * @param argv Array of arguments + * @return 0 on success, non-zero on failure + */ +int cmd_manifest(int argc, char** argv); + /** * @brief Handler for the help command * @@ -39,6 +50,16 @@ int cmd_help(int argc, char** argv); */ int cmd_stage_help(int argc, char** argv); +/** + * @brief Handler for the manifest help command + * + * Displays information about manifest command options. + * + * @param argc Number of arguments + * @param argv Array of arguments + * @return 0 on success, non-zero on failure + */ +int cmd_manifest_help(int argc, char** argv); /** * @brief Handler for unknown commands diff --git a/modules/build/src/checksums.cpp b/modules/build/src/checksums.cpp index e768470..23a4875 100644 --- a/modules/build/src/checksums.cpp +++ b/modules/build/src/checksums.cpp @@ -13,7 +13,6 @@ #include "checksums.hpp" - std::string get_configured_hash_algorithm() { const char* algorithm = dpm_get_config("cryptography", "checksum_algorithm"); @@ -169,4 +168,4 @@ std::string generate_file_checksum(const std::filesystem::path& file_path) } return ss.str(); -} \ No newline at end of file +} diff --git a/modules/build/src/cli_parsers.cpp b/modules/build/src/cli_parsers.cpp index 672d29b..1ec047a 100644 --- a/modules/build/src/cli_parsers.cpp +++ b/modules/build/src/cli_parsers.cpp @@ -237,6 +237,11 @@ Command parse_command(const char* cmd_str) { return CMD_STAGE; } + // Check for stage command, including when it has additional arguments + if (strncmp(cmd_str, "manifest", 8) == 0) { + return CMD_MANIFEST; + } + // Check if cmd_str is a help option if (strcmp(cmd_str, "-h") == 0 || strcmp(cmd_str, "--help") == 0) { return CMD_HELP; diff --git a/modules/build/src/commands.cpp b/modules/build/src/commands.cpp index 336b5e1..ca781b7 100644 --- a/modules/build/src/commands.cpp +++ b/modules/build/src/commands.cpp @@ -1,5 +1,73 @@ #include "commands.hpp" +static int refresh_package_manifest(const std::string& stage_dir, bool force) { + dpm_log(LOG_INFO, ("Refreshing package manifest for: " + stage_dir).c_str()); + return 0; +} + +static int generate_package_manifest(const std::string& stage_dir, bool force) { + dpm_log(LOG_INFO, ("Generating package manifest for: " + stage_dir).c_str()); + return 0; +} + +int cmd_manifest(int argc, char** argv) { + // Parse command line options + bool force = false; + bool refresh_only = false; + bool verbose = false; + bool show_help = false; + std::string stage_dir = ""; + + // Process command-line arguments + for (int i = 1; i < argc; i++) { + std::string arg = argv[i]; + + if (arg == "-f" || arg == "--force") { + force = true; + } else if (arg == "-r" || arg == "--refresh-only") { + refresh_only = true; + } else if (arg == "-v" || arg == "--verbose") { + verbose = true; + } else if (arg == "-h" || arg == "--help" || "help" ) { + show_help = true; + } else if ((arg == "-s" || arg == "--stage") && i + 1 < argc) { + stage_dir = argv[i + 1]; + i++; // Skip the next argument + } + } + + // If help was requested, show it and return + if (show_help) { + return cmd_manifest_help(argc, argv); + } + + // Validate that stage directory is provided + if (stage_dir.empty()) { + dpm_log(LOG_ERROR, "Stage directory is required (--stage/-s)"); + return cmd_manifest_help(argc, argv); + } + + // Expand path if needed + stage_dir = expand_path(stage_dir); + + // Check if stage directory exists + if (!std::filesystem::exists(stage_dir)) { + dpm_log(LOG_ERROR, ("Stage directory does not exist: " + stage_dir).c_str()); + return 1; + } + + // Set verbose logging if requested + if (verbose) { + dpm_set_logging_level(LOG_DEBUG); + } + + // Log the operation being performed + if (refresh_only) { + return refresh_package_manifest(stage_dir, force); + } else { + return generate_package_manifest(stage_dir, force); + } +} int cmd_stage(int argc, char** argv) { // Announce that the stage step is being executed (debug level) @@ -81,6 +149,7 @@ int cmd_help(int argc, char** argv) { dpm_log(LOG_INFO, ""); dpm_log(LOG_INFO, "Available commands:"); dpm_log(LOG_INFO, " stage - Stage a new DPM package directory"); + dpm_log(LOG_INFO, " manifest - Generate or refresh package manifest"); dpm_log(LOG_INFO, " help - Display this help message"); dpm_log(LOG_INFO, ""); dpm_log(LOG_INFO, "Usage: dpm build "); @@ -114,4 +183,17 @@ int cmd_stage_help(int argc, char** argv) { dpm_log(LOG_INFO, " -v, --verbose Enable verbose output"); dpm_log(LOG_INFO, " -h, --help Display this help message"); return 0; +} + +int cmd_manifest_help(int argc, char** argv) { + dpm_log(LOG_INFO, "Usage: dpm build manifest [options]"); + dpm_log(LOG_INFO, ""); + dpm_log(LOG_INFO, "Options:"); + dpm_log(LOG_INFO, " -s, --stage DIR Stage directory path (required)"); + dpm_log(LOG_INFO, " -r, --refresh-only Refresh existing manifest instead of generating a new one"); + dpm_log(LOG_INFO, " -f, --force Force manifest operation even if warnings occur"); + dpm_log(LOG_INFO, " -v, --verbose Enable verbose output"); + dpm_log(LOG_INFO, " -h, --help Display this help message"); + dpm_log(LOG_INFO, ""); + return 0; } \ No newline at end of file