Skip to content

Commit c9ec00b

Browse files
committed
fix(cli): resolve strict warning and cppcheck failures
2 parents 525810a + add987a commit c9ec00b

4 files changed

Lines changed: 72 additions & 29 deletions

File tree

src/commands/InstallCommand.cpp

Lines changed: 66 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,8 @@ namespace vix::commands
12911291
dep.tag = v.at("tag").get<std::string>();
12921292
dep.commit = v.at("commit").get<std::string>();
12931293
dep.type = entry.value("type", "header-only");
1294-
if (v.contains("extensions") && v["extensions"].is_object()) dep.extensions = v["extensions"];
1294+
if (v.contains("extensions") && v["extensions"].is_object())
1295+
dep.extensions = v["extensions"];
12951296
dep.checkout = store_checkout_path(dep.id, dep.commit);
12961297

12971298
return dep;
@@ -1361,8 +1362,10 @@ namespace vix::commands
13611362
item["files"] = make_files_json(files);
13621363
item["executables"] = make_strings_json(executables);
13631364
item["shims"] = make_strings_json(shims);
1364-
if (!dep.extensions.is_null()) item["extensions"] = dep.extensions;
1365-
else item.erase("extensions");
1365+
if (!dep.extensions.is_null())
1366+
item["extensions"] = dep.extensions;
1367+
else
1368+
item.erase("extensions");
13661369
updated = true;
13671370
break;
13681371
}
@@ -1389,7 +1392,8 @@ namespace vix::commands
13891392
{"executables", make_strings_json(executables)},
13901393
{"shims", make_strings_json(shims)},
13911394
};
1392-
if (!dep.extensions.is_null()) newItem["extensions"] = dep.extensions;
1395+
if (!dep.extensions.is_null())
1396+
newItem["extensions"] = dep.extensions;
13931397
arr.push_back(std::move(newItem));
13941398
}
13951399

@@ -2395,24 +2399,43 @@ namespace vix::commands
23952399
static std::vector<fs::path> collect_regular_files(const fs::path &root)
23962400
{
23972401
std::vector<fs::path> files;
2402+
23982403
std::error_code ec;
2399-
if (!fs::exists(root, ec))
2404+
if (!fs::exists(root, ec) || ec)
24002405
return files;
24012406

2402-
for (fs::recursive_directory_iterator it(root, fs::directory_options::skip_permission_denied, ec), end;
2403-
!ec && it != end;
2404-
it.increment(ec))
2405-
{
2406-
if (ec)
2407-
break;
2407+
fs::recursive_directory_iterator it(
2408+
root,
2409+
fs::directory_options::skip_permission_denied,
2410+
ec);
2411+
const fs::recursive_directory_iterator end;
24082412

2413+
if (ec)
2414+
return files;
2415+
2416+
while (it != end)
2417+
{
24092418
const fs::path p = it->path();
2410-
const auto st = fs::symlink_status(p, ec);
2411-
if (ec)
2412-
continue;
24132419

2414-
if (fs::is_regular_file(st) || fs::is_symlink(st))
2415-
files.push_back(fs::relative(p, root).lexically_normal());
2420+
std::error_code entryEc;
2421+
const auto status = fs::symlink_status(p, entryEc);
2422+
2423+
if (!entryEc &&
2424+
(fs::is_regular_file(status) || fs::is_symlink(status)))
2425+
{
2426+
std::error_code relativeEc;
2427+
const fs::path relative = fs::relative(p, root, relativeEc);
2428+
2429+
if (!relativeEc)
2430+
files.push_back(relative.lexically_normal());
2431+
}
2432+
2433+
it.increment(ec);
2434+
if (ec)
2435+
{
2436+
ec.clear();
2437+
break;
2438+
}
24162439
}
24172440

24182441
std::sort(files.begin(), files.end());
@@ -2427,17 +2450,36 @@ namespace vix::commands
24272450
if (!fs::exists(bin, ec) || !fs::is_directory(bin, ec))
24282451
return commands;
24292452

2430-
for (fs::directory_iterator it(bin, ec), end; !ec && it != end; it.increment(ec))
2453+
fs::directory_iterator it(bin, ec);
2454+
const fs::directory_iterator end;
2455+
2456+
if (ec)
2457+
return commands;
2458+
2459+
while (it != end)
24312460
{
2461+
std::error_code entryEc;
2462+
const fs::file_status status = it->symlink_status(entryEc);
2463+
2464+
if (!entryEc &&
2465+
(fs::is_regular_file(status) || fs::is_symlink(status)) &&
2466+
is_executable_filename(it->path()))
2467+
{
2468+
const std::string cmd = executable_command_name(it->path());
2469+
2470+
if (!cmd.empty() &&
2471+
std::find(commands.begin(), commands.end(), cmd) == commands.end())
2472+
{
2473+
commands.push_back(cmd);
2474+
}
2475+
}
2476+
2477+
it.increment(ec);
24322478
if (ec)
2479+
{
2480+
ec.clear();
24332481
break;
2434-
if (!it->is_regular_file(ec) && !it->is_symlink(ec))
2435-
continue;
2436-
if (!is_executable_filename(it->path()))
2437-
continue;
2438-
const std::string cmd = executable_command_name(it->path());
2439-
if (!cmd.empty() && std::find(commands.begin(), commands.end(), cmd) == commands.end())
2440-
commands.push_back(cmd);
2482+
}
24412483
}
24422484

24432485
std::sort(commands.begin(), commands.end());

src/commands/RunCommand.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ namespace
927927
#endif
928928
}
929929

930-
int run_resolved_project(
930+
[[maybe_unused]] int run_resolved_project(
931931
const app::AppProjectResolveResult &resolved,
932932
const Options &opt,
933933
bool showUi)
@@ -1167,7 +1167,7 @@ namespace
11671167
return 0;
11681168
}
11691169

1170-
int run_project_with_presets(
1170+
[[maybe_unused]] int run_project_with_presets(
11711171
const fs::path &projectDir,
11721172
const Options &opt,
11731173
bool showUi)

src/commands/db/DbMigrator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace vix::commands::db::migrator
3535
return cfg.engine == DbEngine::SQLite;
3636
}
3737

38-
bool validate_migration_inputs(const DbConfig &cfg)
38+
[[maybe_unused]] bool validate_migration_inputs(const DbConfig &cfg)
3939
{
4040
if (!is_sqlite(cfg))
4141
{
@@ -81,7 +81,7 @@ namespace vix::commands::db::migrator
8181
return true;
8282
}
8383

84-
void print_migration_summary(const DbConfig &cfg)
84+
[[maybe_unused]] void print_migration_summary(const DbConfig &cfg)
8585
{
8686
output::step(std::cout, "Database Migrations");
8787

@@ -96,6 +96,7 @@ namespace vix::commands::db::migrator
9696
const DbOptions &options)
9797
{
9898
(void)options;
99+
(void)cfg;
99100

100101
#ifndef VIX_CLI_HAS_DB
101102
output::error(

src/commands/run/RunFlow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ namespace vix::commands::RunCommand::detail
972972
if (has("build-ninja"))
973973
return "build-ninja";
974974

975-
return runs[0];
975+
return runs.empty() ? std::string("run-ninja") : runs.front();
976976
}
977977

978978
bool has_cmake_cache(const fs::path &buildDir)

0 commit comments

Comments
 (0)