Indent every scope and put opening braces on the signature line

Namespace and extern "C" bodies are indented a level, so nesting is
visible from the indentation rather than only from the braces. Opening
braces stay on the line that opens the scope, including function
definitions, which previously carried theirs on a line of their own.
This commit is contained in:
2026-08-15 23:47:43 -04:00
parent 9fd7d2f433
commit 12a4f68025
13 changed files with 634 additions and 709 deletions

View File

@@ -33,127 +33,120 @@
#include <vector>
namespace {
/**
* @brief Prints the CLI usage message
*/
void show_help()
{
std::printf(
"Usage: dpm [options] [module] [module args...]\n"
"\n"
"Options:\n"
" -c, --config-dir PATH Configuration directory (default /etc/dpm/conf.d/)\n"
" -m, --module-path PATH Module directory (overrides configuration)\n"
" -r, --root PATH Target root for package operations (default /)\n"
" -L, --log-level LEVEL FATAL, ERROR, WARN, INFO, or DEBUG\n"
" -l, --list-modules List available modules\n"
" -h, --help Show this help message\n"
"\n"
"For module-specific help, use: dpm <module> help\n");
}
/**
* @brief Parses a log level name
*
* @param name The level name (case-insensitive)
* @return The DPM_LOG_* level, or -1 if unrecognized
*/
int level_from_name(const char* name)
{
if (strcasecmp(name, "FATAL") == 0) { return DPM_LOG_FATAL; }
if (strcasecmp(name, "ERROR") == 0) { return DPM_LOG_ERROR; }
if (strcasecmp(name, "WARN") == 0) { return DPM_LOG_WARN; }
if (strcasecmp(name, "INFO") == 0) { return DPM_LOG_INFO; }
if (strcasecmp(name, "DEBUG") == 0) { return DPM_LOG_DEBUG; }
return -1;
}
/**
* @brief Matches an argument against an option's short and long forms
*
* Recognizes the separate-value forms and the --option=value form.
*
* @param arg The command-line argument to test
* @param short_form The option's short form (e.g. "-c")
* @param long_form The option's long form (e.g. "--config-dir")
* @param inline_value Receives the text after '=' for the inline
* form, or NULL when the value is in the next
* argument
* @return true if the argument is this option
*/
bool option_matches(const char* arg, const char* short_form,
const char* long_form, const char** inline_value)
{
if (std::strcmp(arg, short_form) == 0 ||
std::strcmp(arg, long_form) == 0) {
*inline_value = nullptr;
return true;
/**
* @brief Prints the CLI usage message
*/
void show_help() {
std::printf(
"Usage: dpm [options] [module] [module args...]\n"
"\n"
"Options:\n"
" -c, --config-dir PATH Configuration directory (default /etc/dpm/conf.d/)\n"
" -m, --module-path PATH Module directory (overrides configuration)\n"
" -r, --root PATH Target root for package operations (default /)\n"
" -L, --log-level LEVEL FATAL, ERROR, WARN, INFO, or DEBUG\n"
" -l, --list-modules List available modules\n"
" -h, --help Show this help message\n"
"\n"
"For module-specific help, use: dpm <module> help\n");
}
size_t len = std::strlen(long_form);
if (std::strncmp(arg, long_form, len) == 0 && arg[len] == '=') {
*inline_value = arg + len + 1;
return true;
/**
* @brief Parses a log level name
*
* @param name The level name (case-insensitive)
* @return The DPM_LOG_* level, or -1 if unrecognized
*/
int level_from_name(const char* name) {
if (strcasecmp(name, "FATAL") == 0) { return DPM_LOG_FATAL; }
if (strcasecmp(name, "ERROR") == 0) { return DPM_LOG_ERROR; }
if (strcasecmp(name, "WARN") == 0) { return DPM_LOG_WARN; }
if (strcasecmp(name, "INFO") == 0) { return DPM_LOG_INFO; }
if (strcasecmp(name, "DEBUG") == 0) { return DPM_LOG_DEBUG; }
return -1;
}
return false;
}
/**
* @brief Matches an argument against an option's short and long forms
*
* Recognizes the separate-value forms and the --option=value form.
*
* @param arg The command-line argument to test
* @param short_form The option's short form (e.g. "-c")
* @param long_form The option's long form (e.g. "--config-dir")
* @param inline_value Receives the text after '=' for the inline
* form, or NULL when the value is in the next
* argument
* @return true if the argument is this option
*/
bool option_matches(const char* arg, const char* short_form,
const char* long_form, const char** inline_value) {
if (std::strcmp(arg, short_form) == 0 ||
std::strcmp(arg, long_form) == 0) {
*inline_value = nullptr;
return true;
}
/**
* @brief Prints the table of available modules
*
* @param ctx The libdpm-core context
* @return 0 on success, 1 on failure
*/
int list_modules(dpm_ctx* ctx)
{
dpm_cursor* cur = dpm_list_modules(ctx);
if (!cur) {
const char* err = dpm_last_error(ctx);
std::fprintf(stderr, "dpm: %s\n", err ? err : "module listing failed");
return 1;
size_t len = std::strlen(long_form);
if (std::strncmp(arg, long_form, len) == 0 && arg[len] == '=') {
*inline_value = arg + len + 1;
return true;
}
return false;
}
std::vector<dpm_module_info> infos;
dpm_module_info info;
while (dpm_cursor_next(cur, &info) == 0) {
infos.push_back(info);
}
dpm_cursor_free(cur);
/**
* @brief Prints the table of available modules
*
* @param ctx The libdpm-core context
* @return 0 on success, 1 on failure
*/
int list_modules(dpm_ctx* ctx) {
dpm_cursor* cur = dpm_list_modules(ctx);
if (!cur) {
const char* err = dpm_last_error(ctx);
std::fprintf(stderr, "dpm: %s\n", err ? err : "module listing failed");
return 1;
}
std::vector<dpm_module_info> infos;
dpm_module_info info;
while (dpm_cursor_next(cur, &info) == 0) {
infos.push_back(info);
}
dpm_cursor_free(cur);
if (infos.empty()) {
std::printf("No valid modules found in %s\n", dpm_module_path(ctx));
return 0;
}
size_t name_w = std::strlen("MODULE");
size_t version_w = std::strlen("VERSION");
for (const auto& i : infos) {
name_w = std::max(name_w, std::strlen(i.name));
version_w = std::max(version_w, std::strlen(i.version));
}
std::printf("Available DPM modules:\n\n");
std::printf("%-*s %-*s %s\n",
static_cast<int>(name_w), "MODULE",
static_cast<int>(version_w), "VERSION",
"DESCRIPTION");
for (const auto& i : infos) {
std::printf("%-*s %-*s %s\n",
static_cast<int>(name_w), i.name,
static_cast<int>(version_w), i.version,
i.description);
}
std::printf("\nUse 'dpm <module> help' for module-specific help.\n");
if (infos.empty()) {
std::printf("No valid modules found in %s\n", dpm_module_path(ctx));
return 0;
}
size_t name_w = std::strlen("MODULE");
size_t version_w = std::strlen("VERSION");
for (const auto& i : infos) {
name_w = std::max(name_w, std::strlen(i.name));
version_w = std::max(version_w, std::strlen(i.version));
}
std::printf("Available DPM modules:\n\n");
std::printf("%-*s %-*s %s\n",
static_cast<int>(name_w), "MODULE",
static_cast<int>(version_w), "VERSION",
"DESCRIPTION");
for (const auto& i : infos) {
std::printf("%-*s %-*s %s\n",
static_cast<int>(name_w), i.name,
static_cast<int>(version_w), i.version,
i.description);
}
std::printf("\nUse 'dpm <module> help' for module-specific help.\n");
return 0;
}
} // namespace
int main(int argc, char** argv)
{
int main(int argc, char** argv) {
dpm_open_overrides overrides = {nullptr, nullptr, nullptr, -1};
bool list = false;