improved consistency in argument handling, introduction of dpm_con (not everything needs to be in the log)
This commit is contained in:
@@ -147,6 +147,7 @@ int cmd_stage(int argc, char** argv) {
|
||||
// Validate options
|
||||
int validate_result = validate_build_options(options);
|
||||
if (validate_result != 0) {
|
||||
cmd_stage_help(argc, argv);
|
||||
return validate_result;
|
||||
}
|
||||
|
||||
@@ -271,19 +272,19 @@ int cmd_sign(int argc, char** argv) {
|
||||
}
|
||||
|
||||
int cmd_help(int argc, char** argv) {
|
||||
dpm_log(LOG_INFO, "DPM Build Module - Creates DPM packages.");
|
||||
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, " metadata - Generate or refresh package metadata");
|
||||
dpm_log(LOG_INFO, " sign - Sign a package or package stage directory");
|
||||
dpm_log(LOG_INFO, " seal - Seal a package stage directory into final format");
|
||||
dpm_log(LOG_INFO, " unseal - Unseal a package back to stage format");
|
||||
dpm_log(LOG_INFO, " help - Display this help message");
|
||||
dpm_log(LOG_INFO, "");
|
||||
dpm_log(LOG_INFO, "Usage: dpm build <command>");
|
||||
dpm_log(LOG_INFO, "");
|
||||
dpm_log(LOG_INFO, "For command-specific help, use: dpm build <command> --help");
|
||||
dpm_con(LOG_INFO, "DPM Build Module - Creates DPM packages.");
|
||||
dpm_con(LOG_INFO, "");
|
||||
dpm_con(LOG_INFO, "Available commands:");
|
||||
dpm_con(LOG_INFO, " stage - Stage a new DPM package directory");
|
||||
dpm_con(LOG_INFO, " metadata - Generate or refresh package metadata");
|
||||
dpm_con(LOG_INFO, " sign - Sign a package or package stage directory");
|
||||
dpm_con(LOG_INFO, " seal - Seal a package stage directory into final format");
|
||||
dpm_con(LOG_INFO, " unseal - Unseal a package back to stage format");
|
||||
dpm_con(LOG_INFO, " help - Display this help message");
|
||||
dpm_con(LOG_INFO, "");
|
||||
dpm_con(LOG_INFO, "Usage: dpm build <command>");
|
||||
dpm_con(LOG_INFO, "");
|
||||
dpm_con(LOG_INFO, "For command-specific help, use: dpm build <command> --help");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -291,76 +292,76 @@ int cmd_help(int argc, char** argv) {
|
||||
int cmd_unknown(const char* command, int argc, char** argv) {
|
||||
std::string msg = "Unknown command: ";
|
||||
msg += (command ? command : "");
|
||||
dpm_log(LOG_WARN, msg.c_str());
|
||||
dpm_log(LOG_WARN, "Run 'dpm build help' for a list of available commands");
|
||||
dpm_con(LOG_WARN, msg.c_str());
|
||||
dpm_con(LOG_WARN, "Run 'dpm build help' for a list of available commands");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int cmd_metadata_help(int argc, char** argv) {
|
||||
dpm_log(LOG_INFO, "Usage: dpm build metadata [options]");
|
||||
dpm_log(LOG_INFO, "");
|
||||
dpm_log(LOG_INFO, "Options:");
|
||||
dpm_log(LOG_INFO, " -s, --stage DIR Package stage directory path (required)");
|
||||
dpm_log(LOG_INFO, " -r, --refresh Refresh existing metadata (use for updating)");
|
||||
dpm_log(LOG_INFO, "");
|
||||
dpm_log(LOG_INFO, "For new metadata generation (when not using --refresh):");
|
||||
dpm_log(LOG_INFO, " -n, --name NAME Package name (required for new generation)");
|
||||
dpm_log(LOG_INFO, " -V, --version VERSION Package version (required for new generation)");
|
||||
dpm_log(LOG_INFO, " -a, --architecture ARCH Package architecture (required for new generation)");
|
||||
dpm_log(LOG_INFO, "");
|
||||
dpm_log(LOG_INFO, "Additional options:");
|
||||
dpm_log(LOG_INFO, " -f, --force Force 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, "");
|
||||
dpm_log(LOG_INFO, "Examples:");
|
||||
dpm_log(LOG_INFO, " # Refresh metadata in an existing package stage:");
|
||||
dpm_log(LOG_INFO, " dpm build metadata --stage=./my-package-1.0.x86_64 --refresh");
|
||||
dpm_log(LOG_INFO, "");
|
||||
dpm_log(LOG_INFO, " # Generate new metadata for a package stage:");
|
||||
dpm_log(LOG_INFO, " dpm build metadata --stage=./my-package-1.0.x86_64 --name=my-package --version=1.0 --architecture=x86_64");
|
||||
dpm_con(LOG_INFO, "Usage: dpm build metadata [options]");
|
||||
dpm_con(LOG_INFO, "");
|
||||
dpm_con(LOG_INFO, "Options:");
|
||||
dpm_con(LOG_INFO, " -s, --stage DIR Package stage directory path (required)");
|
||||
dpm_con(LOG_INFO, " -r, --refresh Refresh existing metadata (use for updating)");
|
||||
dpm_con(LOG_INFO, "");
|
||||
dpm_con(LOG_INFO, "For new metadata generation (when not using --refresh):");
|
||||
dpm_con(LOG_INFO, " -n, --name NAME Package name (required for new generation)");
|
||||
dpm_con(LOG_INFO, " -V, --version VERSION Package version (required for new generation)");
|
||||
dpm_con(LOG_INFO, " -a, --architecture ARCH Package architecture (required for new generation)");
|
||||
dpm_con(LOG_INFO, "");
|
||||
dpm_con(LOG_INFO, "Additional options:");
|
||||
dpm_con(LOG_INFO, " -f, --force Force operation even if warnings occur");
|
||||
dpm_con(LOG_INFO, " -v, --verbose Enable verbose output");
|
||||
dpm_con(LOG_INFO, " -h, --help Display this help message");
|
||||
dpm_con(LOG_INFO, "");
|
||||
dpm_con(LOG_INFO, "Examples:");
|
||||
dpm_con(LOG_INFO, " # Refresh metadata in an existing package stage:");
|
||||
dpm_con(LOG_INFO, " dpm build metadata --stage=./my-package-1.0.x86_64 --refresh");
|
||||
dpm_con(LOG_INFO, "");
|
||||
dpm_con(LOG_INFO, " # Generate new metadata for a package stage:");
|
||||
dpm_con(LOG_INFO, " dpm build metadata --stage=./my-package-1.0.x86_64 --name=my-package --version=1.0 --architecture=x86_64");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cmd_stage_help(int argc, char** argv) {
|
||||
dpm_log(LOG_INFO, "Usage: dpm build stage [options]");
|
||||
dpm_log(LOG_INFO, "");
|
||||
dpm_log(LOG_INFO, "Options:");
|
||||
dpm_log(LOG_INFO, " -o, --output DIR Directory to save the staged package (required)");
|
||||
dpm_log(LOG_INFO, " -c, --contents DIR Directory with package contents (required)");
|
||||
dpm_log(LOG_INFO, " -H, --hooks DIR Directory with package hooks (optional)");
|
||||
dpm_log(LOG_INFO, " -n, --name NAME Package name (required)");
|
||||
dpm_log(LOG_INFO, " -V, --version VERSION Package version (required)");
|
||||
dpm_log(LOG_INFO, " -a, --architecture ARCH Package architecture (required, e.g., x86_64)");
|
||||
dpm_log(LOG_INFO, " -O, --os OS Package OS (optional, e.g., dhl2)");
|
||||
dpm_log(LOG_INFO, " -f, --force Force package staging even if warnings occur");
|
||||
dpm_log(LOG_INFO, " -v, --verbose Enable verbose output");
|
||||
dpm_log(LOG_INFO, " -h, --help Display this help message");
|
||||
dpm_con(LOG_INFO, "Usage: dpm build stage [options]");
|
||||
dpm_con(LOG_INFO, "");
|
||||
dpm_con(LOG_INFO, "Options:");
|
||||
dpm_con(LOG_INFO, " -o, --output DIR Directory to save the staged package (required)");
|
||||
dpm_con(LOG_INFO, " -c, --contents DIR Directory with package contents (required)");
|
||||
dpm_con(LOG_INFO, " -H, --hooks DIR Directory with package hooks (optional)");
|
||||
dpm_con(LOG_INFO, " -n, --name NAME Package name (required)");
|
||||
dpm_con(LOG_INFO, " -V, --version VERSION Package version (required)");
|
||||
dpm_con(LOG_INFO, " -a, --architecture ARCH Package architecture (required, e.g., x86_64)");
|
||||
dpm_con(LOG_INFO, " -O, --os OS Package OS (optional, e.g., dhl2)");
|
||||
dpm_con(LOG_INFO, " -f, --force Force package staging even if warnings occur");
|
||||
dpm_con(LOG_INFO, " -v, --verbose Enable verbose output");
|
||||
dpm_con(LOG_INFO, " -h, --help Display this help message");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cmd_sign_help(int argc, char** argv) {
|
||||
dpm_log(LOG_INFO, "Usage: dpm build sign [options]");
|
||||
dpm_log(LOG_INFO, "");
|
||||
dpm_log(LOG_INFO, "Sign a DPM package or package stage directory using GPG.");
|
||||
dpm_log(LOG_INFO, "");
|
||||
dpm_log(LOG_INFO, "Options:");
|
||||
dpm_log(LOG_INFO, " -k, --key-id ID GPG key ID or email to use for signing (required)");
|
||||
dpm_log(LOG_INFO, " -s, --stage DIR Package stage directory to sign");
|
||||
dpm_log(LOG_INFO, " -p, --package FILE Package file to sign");
|
||||
dpm_log(LOG_INFO, " -f, --force Force signing 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, "");
|
||||
dpm_log(LOG_INFO, "Either --stage or --package must be specified, but not both.");
|
||||
dpm_log(LOG_INFO, "");
|
||||
dpm_log(LOG_INFO, "Examples:");
|
||||
dpm_log(LOG_INFO, " dpm build sign --key-id=\"user@example.com\" --stage=./my-package-1.0.x86_64");
|
||||
dpm_log(LOG_INFO, " dpm build sign --key-id=\"AB123CD456\" --package=./my-package-1.0.x86_64.dpm");
|
||||
dpm_con(LOG_INFO, "Usage: dpm build sign [options]");
|
||||
dpm_con(LOG_INFO, "");
|
||||
dpm_con(LOG_INFO, "Sign a DPM package or package stage directory using GPG.");
|
||||
dpm_con(LOG_INFO, "");
|
||||
dpm_con(LOG_INFO, "Options:");
|
||||
dpm_con(LOG_INFO, " -k, --key-id ID GPG key ID or email to use for signing (required)");
|
||||
dpm_con(LOG_INFO, " -s, --stage DIR Package stage directory to sign");
|
||||
dpm_con(LOG_INFO, " -p, --package FILE Package file to sign");
|
||||
dpm_con(LOG_INFO, " -f, --force Force signing even if warnings occur");
|
||||
dpm_con(LOG_INFO, " -v, --verbose Enable verbose output");
|
||||
dpm_con(LOG_INFO, " -h, --help Display this help message");
|
||||
dpm_con(LOG_INFO, "");
|
||||
dpm_con(LOG_INFO, "Either --stage or --package must be specified, but not both.");
|
||||
dpm_con(LOG_INFO, "");
|
||||
dpm_con(LOG_INFO, "Examples:");
|
||||
dpm_con(LOG_INFO, " dpm build sign --key-id=\"user@example.com\" --stage=./my-package-1.0.x86_64");
|
||||
dpm_con(LOG_INFO, " dpm build sign --key-id=\"AB123CD456\" --package=./my-package-1.0.x86_64.dpm");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int cmd_unseal(int argc, char** argv) {
|
||||
// Parse command line options
|
||||
std::string input_path = "";
|
||||
@@ -402,13 +403,13 @@ int cmd_unseal(int argc, char** argv) {
|
||||
|
||||
// Validate that input path is provided
|
||||
if (input_path.empty()) {
|
||||
dpm_log(LOG_ERROR, "Input path is required (--input/-i)");
|
||||
dpm_con(LOG_ERROR, "Input path is required (--input/-i)");
|
||||
return cmd_unseal_help(argc, argv);
|
||||
}
|
||||
|
||||
// Check for invalid option combinations
|
||||
if (components_mode && !output_dir.empty()) {
|
||||
dpm_log(LOG_ERROR, "Output directory (-o/--output) cannot be specified in components mode (-c/--components)");
|
||||
dpm_con(LOG_ERROR, "Output directory (-o/--output) cannot be specified in components mode (-c/--components)");
|
||||
return cmd_unseal_help(argc, argv);
|
||||
}
|
||||
|
||||
@@ -417,7 +418,7 @@ int cmd_unseal(int argc, char** argv) {
|
||||
|
||||
// Check if input path exists
|
||||
if (!std::filesystem::exists(input_path)) {
|
||||
dpm_log(LOG_ERROR, ("Input path does not exist: " + input_path).c_str());
|
||||
dpm_con(LOG_ERROR, ("Input path does not exist: " + input_path).c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -430,7 +431,7 @@ int cmd_unseal(int argc, char** argv) {
|
||||
if (components_mode) {
|
||||
// We're unsealing components of a stage directory
|
||||
if (!std::filesystem::is_directory(input_path)) {
|
||||
dpm_log(LOG_ERROR, ("Input path must be a directory in components mode: " + input_path).c_str());
|
||||
dpm_con(LOG_ERROR, ("Input path must be a directory in components mode: " + input_path).c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -439,7 +440,7 @@ int cmd_unseal(int argc, char** argv) {
|
||||
} else {
|
||||
// We're unsealing a package file
|
||||
if (std::filesystem::is_directory(input_path)) {
|
||||
dpm_log(LOG_ERROR, ("Input path must be a file when not in components mode: " + input_path).c_str());
|
||||
dpm_con(LOG_ERROR, ("Input path must be a file when not in components mode: " + input_path).c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -449,28 +450,28 @@ int cmd_unseal(int argc, char** argv) {
|
||||
}
|
||||
|
||||
int cmd_unseal_help(int argc, char** argv) {
|
||||
dpm_log(LOG_INFO, "Usage: dpm build unseal [options]");
|
||||
dpm_log(LOG_INFO, "");
|
||||
dpm_log(LOG_INFO, "Unseals a DPM package file or package stage components.");
|
||||
dpm_log(LOG_INFO, "");
|
||||
dpm_log(LOG_INFO, "Options:");
|
||||
dpm_log(LOG_INFO, " -i, --input PATH Path to package file or stage directory (required)");
|
||||
dpm_log(LOG_INFO, " -o, --output DIR Directory to extract package to (optional, package mode only)");
|
||||
dpm_log(LOG_INFO, " -c, --components Component mode: unseal components in a stage directory");
|
||||
dpm_log(LOG_INFO, " Without this flag, input is treated as a package file");
|
||||
dpm_log(LOG_INFO, " -f, --force Force unsealing even if warnings occur or directory exists");
|
||||
dpm_log(LOG_INFO, " -v, --verbose Enable verbose output");
|
||||
dpm_log(LOG_INFO, " -h, --help Display this help message");
|
||||
dpm_log(LOG_INFO, "");
|
||||
dpm_log(LOG_INFO, "Examples:");
|
||||
dpm_log(LOG_INFO, " # Unseal a package file to a directory:");
|
||||
dpm_log(LOG_INFO, " dpm build unseal --input=./my-package-1.0.x86_64.dpm");
|
||||
dpm_log(LOG_INFO, "");
|
||||
dpm_log(LOG_INFO, " # Unseal a package file to a specific directory:");
|
||||
dpm_log(LOG_INFO, " dpm build unseal --input=./my-package-1.0.x86_64.dpm --output=./extract");
|
||||
dpm_log(LOG_INFO, "");
|
||||
dpm_log(LOG_INFO, " # Unseal components in a stage directory:");
|
||||
dpm_log(LOG_INFO, " dpm build unseal --input=./my-package-1.0.x86_64 --components");
|
||||
dpm_con(LOG_INFO, "Usage: dpm build unseal [options]");
|
||||
dpm_con(LOG_INFO, "");
|
||||
dpm_con(LOG_INFO, "Unseals a DPM package file or package stage components.");
|
||||
dpm_con(LOG_INFO, "");
|
||||
dpm_con(LOG_INFO, "Options:");
|
||||
dpm_con(LOG_INFO, " -i, --input PATH Path to package file or stage directory (required)");
|
||||
dpm_con(LOG_INFO, " -o, --output DIR Directory to extract package to (optional, package mode only)");
|
||||
dpm_con(LOG_INFO, " -c, --components Component mode: unseal components in a stage directory");
|
||||
dpm_con(LOG_INFO, " Without this flag, input is treated as a package file");
|
||||
dpm_con(LOG_INFO, " -f, --force Force unsealing even if warnings occur or directory exists");
|
||||
dpm_con(LOG_INFO, " -v, --verbose Enable verbose output");
|
||||
dpm_con(LOG_INFO, " -h, --help Display this help message");
|
||||
dpm_con(LOG_INFO, "");
|
||||
dpm_con(LOG_INFO, "Examples:");
|
||||
dpm_con(LOG_INFO, " # Unseal a package file to a directory:");
|
||||
dpm_con(LOG_INFO, " dpm build unseal --input=./my-package-1.0.x86_64.dpm");
|
||||
dpm_con(LOG_INFO, "");
|
||||
dpm_con(LOG_INFO, " # Unseal a package file to a specific directory:");
|
||||
dpm_con(LOG_INFO, " dpm build unseal --input=./my-package-1.0.x86_64.dpm --output=./extract");
|
||||
dpm_con(LOG_INFO, "");
|
||||
dpm_con(LOG_INFO, " # Unseal components in a stage directory:");
|
||||
dpm_con(LOG_INFO, " dpm build unseal --input=./my-package-1.0.x86_64 --components");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -515,7 +516,7 @@ int cmd_seal(int argc, char** argv) {
|
||||
|
||||
// Validate that stage directory is provided
|
||||
if (stage_dir.empty()) {
|
||||
dpm_log(LOG_ERROR, "Stage directory is required (--stage/-s)");
|
||||
dpm_con(LOG_ERROR, "Stage directory is required (--stage/-s)");
|
||||
return cmd_seal_help(argc, argv);
|
||||
}
|
||||
|
||||
@@ -524,7 +525,7 @@ int cmd_seal(int argc, char** argv) {
|
||||
|
||||
// Check if stage directory exists
|
||||
if (!std::filesystem::exists(stage_dir)) {
|
||||
dpm_log(LOG_ERROR, ("Stage directory does not exist: " + stage_dir).c_str());
|
||||
dpm_con(LOG_ERROR, ("Stage directory does not exist: " + stage_dir).c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -542,22 +543,22 @@ int cmd_seal(int argc, char** argv) {
|
||||
}
|
||||
|
||||
int cmd_seal_help(int argc, char** argv) {
|
||||
dpm_log(LOG_INFO, "Usage: dpm build seal [options]");
|
||||
dpm_log(LOG_INFO, "");
|
||||
dpm_log(LOG_INFO, "Seals a package stage directory by replacing contents, metadata,");
|
||||
dpm_log(LOG_INFO, "hooks, and signatures directories with gzipped tarballs.");
|
||||
dpm_log(LOG_INFO, "");
|
||||
dpm_log(LOG_INFO, "Options:");
|
||||
dpm_log(LOG_INFO, " -s, --stage DIR Package stage directory to seal (required)");
|
||||
dpm_log(LOG_INFO, " -o, --output DIR Output directory for the finalized package (optional)");
|
||||
dpm_log(LOG_INFO, " -f, --force Force sealing even if warnings occur");
|
||||
dpm_log(LOG_INFO, " -z, --finalize Also compress the entire stage as a final package");
|
||||
dpm_log(LOG_INFO, " -v, --verbose Enable verbose output");
|
||||
dpm_log(LOG_INFO, " -h, --help Display this help message");
|
||||
dpm_log(LOG_INFO, "");
|
||||
dpm_log(LOG_INFO, "Examples:");
|
||||
dpm_log(LOG_INFO, " dpm build seal --stage=./my-package-1.0.x86_64");
|
||||
dpm_log(LOG_INFO, " dpm build seal --stage=./my-package-1.0.x86_64 --finalize");
|
||||
dpm_log(LOG_INFO, " dpm build seal --stage=./my-package-1.0.x86_64 --finalize --output=/tmp");
|
||||
dpm_con(LOG_INFO, "Usage: dpm build seal [options]");
|
||||
dpm_con(LOG_INFO, "");
|
||||
dpm_con(LOG_INFO, "Seals a package stage directory by replacing contents, metadata,");
|
||||
dpm_con(LOG_INFO, "hooks, and signatures directories with gzipped tarballs.");
|
||||
dpm_con(LOG_INFO, "");
|
||||
dpm_con(LOG_INFO, "Options:");
|
||||
dpm_con(LOG_INFO, " -s, --stage DIR Package stage directory to seal (required)");
|
||||
dpm_con(LOG_INFO, " -o, --output DIR Output directory for the finalized package (optional)");
|
||||
dpm_con(LOG_INFO, " -f, --force Force sealing even if warnings occur");
|
||||
dpm_con(LOG_INFO, " -z, --finalize Also compress the entire stage as a final package");
|
||||
dpm_con(LOG_INFO, " -v, --verbose Enable verbose output");
|
||||
dpm_con(LOG_INFO, " -h, --help Display this help message");
|
||||
dpm_con(LOG_INFO, "");
|
||||
dpm_con(LOG_INFO, "Examples:");
|
||||
dpm_con(LOG_INFO, " dpm build seal --stage=./my-package-1.0.x86_64");
|
||||
dpm_con(LOG_INFO, " dpm build seal --stage=./my-package-1.0.x86_64 --finalize");
|
||||
dpm_con(LOG_INFO, " dpm build seal --stage=./my-package-1.0.x86_64 --finalize --output=/tmp");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user