Skip to content

Commit 10d1c49

Browse files
committed
fix(cli): remove unused functions, fix shadow warnings and clean parameters
- remove dead helper functions across commands - fix -Wshadow in CheckFlow by using explicit variable names - remove unused parameter in UpgradeCommand - clean CLI codebase for zero-warning build (-Wall -Wextra -Wshadow) ensures cleaner, safer and production-grade CLI code
2 parents 3220348 + 60a618b commit 10d1c49

7 files changed

Lines changed: 22 additions & 171 deletions

File tree

src/commands/AddCommand.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -418,25 +418,6 @@ namespace vix::commands
418418
return 0;
419419
}
420420

421-
static void print_commit_missing_help(
422-
const std::string &pkgId,
423-
const std::string &repoUrl,
424-
const std::string &tag,
425-
const std::string &commit)
426-
{
427-
vix::cli::util::warn_line(std::cerr, "The registry entry points to a commit that is not reachable in the remote repository.");
428-
vix::cli::util::warn_line(std::cerr, "This usually happens when the tag/commit was not pushed, or history was rewritten (force-push/rebase).");
429-
std::cerr << "\n";
430-
vix::cli::util::kv(std::cout, "package", pkgId);
431-
vix::cli::util::kv(std::cout, "repo", repoUrl);
432-
vix::cli::util::kv(std::cout, "tag", tag);
433-
vix::cli::util::kv(std::cout, "commit", commit);
434-
std::cout << "\n";
435-
vix::cli::util::warn_line(std::cerr, "Fix:");
436-
vix::cli::util::warn_line(std::cerr, " - Ensure the tag exists on origin: git push --tags");
437-
vix::cli::util::warn_line(std::cerr, " - Or publish a new version with a valid tag/commit (recommended).");
438-
}
439-
440421
static std::optional<PkgSpec> parse_dep_obj_v1(const json &d)
441422
{
442423
if (!d.is_object())

src/commands/InstallCommand.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,6 @@ namespace vix::commands
147147
return global_root_dir() / "installed.json";
148148
}
149149

150-
static std::string to_lower(std::string s)
151-
{
152-
std::transform(
153-
s.begin(),
154-
s.end(),
155-
s.begin(),
156-
[](unsigned char c)
157-
{ return static_cast<char>(std::tolower(c)); });
158-
return s;
159-
}
160-
161150
static std::string trim_copy(std::string s)
162151
{
163152
auto isws = [](unsigned char c)

src/commands/PublishCommand.cpp

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -157,33 +157,6 @@ namespace vix::commands
157157
std::string err;
158158
};
159159

160-
static std::string join_for_log(const std::vector<std::string> &args)
161-
{
162-
std::ostringstream oss;
163-
for (size_t i = 0; i < args.size(); ++i)
164-
{
165-
if (i)
166-
oss << ' ';
167-
const std::string &a = args[i];
168-
const bool needsQuotes = (a.find(' ') != std::string::npos) || (a.find('"') != std::string::npos);
169-
if (!needsQuotes)
170-
{
171-
oss << a;
172-
continue;
173-
}
174-
oss << '"';
175-
for (char c : a)
176-
{
177-
if (c == '"')
178-
oss << "\\\"";
179-
else
180-
oss << c;
181-
}
182-
oss << '"';
183-
}
184-
return oss.str();
185-
}
186-
187160
#if defined(_WIN32)
188161

189162
static std::string win_last_error()
@@ -578,24 +551,6 @@ namespace vix::commands
578551
return std::nullopt;
579552
}
580553

581-
static std::optional<std::string> read_vix_json_string(const fs::path &repoRoot, const char *key)
582-
{
583-
const fs::path p = repoRoot / "vix.json";
584-
if (!file_exists_nonempty(p))
585-
return std::nullopt;
586-
587-
try
588-
{
589-
const json j = read_json_or_throw(p);
590-
if (j.is_object() && j.contains(key) && j[key].is_string())
591-
return j[key].get<std::string>();
592-
}
593-
catch (...)
594-
{
595-
}
596-
return std::nullopt;
597-
}
598-
599554
static json read_vix_json_object(const fs::path &repoRoot)
600555
{
601556
const fs::path p = repoRoot / "vix.json";
@@ -658,20 +613,6 @@ namespace vix::commands
658613
return {};
659614
}
660615

661-
static json ensure_object(json &o, const char *key)
662-
{
663-
if (!o.contains(key) || !o[key].is_object())
664-
o[key] = json::object();
665-
return o[key];
666-
}
667-
668-
static json ensure_array(json &o, const char *key)
669-
{
670-
if (!o.contains(key) || !o[key].is_array())
671-
o[key] = json::array();
672-
return o[key];
673-
}
674-
675616
static std::optional<std::pair<std::string, std::string>> infer_from_git_remote()
676617
{
677618
const auto r = run_process_capture({"git", "remote", "get-url", "origin"});
@@ -758,13 +699,6 @@ namespace vix::commands
758699
return r.exitCode == 0;
759700
}
760701

761-
static bool gh_workflow_run_by_file(const std::string &repo, const std::string &workflowFile)
762-
{
763-
// stable: target the workflow file, not the display name
764-
const auto r = run_process_capture({"gh", "workflow", "run", workflowFile, "--repo", repo});
765-
return r.exitCode == 0;
766-
}
767-
768702
static PublishOptions parse_args_or_throw(const std::vector<std::string> &args)
769703
{
770704
PublishOptions opt;

src/commands/UnpublishCommand.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -134,33 +134,6 @@ namespace vix::commands
134134
std::string err;
135135
};
136136

137-
static std::string join_for_log(const std::vector<std::string> &args)
138-
{
139-
std::ostringstream oss;
140-
for (size_t i = 0; i < args.size(); ++i)
141-
{
142-
if (i)
143-
oss << ' ';
144-
const std::string &a = args[i];
145-
const bool needsQuotes = (a.find(' ') != std::string::npos) || (a.find('"') != std::string::npos);
146-
if (!needsQuotes)
147-
{
148-
oss << a;
149-
continue;
150-
}
151-
oss << '"';
152-
for (char c : a)
153-
{
154-
if (c == '"')
155-
oss << "\\\"";
156-
else
157-
oss << c;
158-
}
159-
oss << '"';
160-
}
161-
return oss.str();
162-
}
163-
164137
#if defined(_WIN32)
165138

166139
static std::string win_last_error()

src/commands/UpgradeCommand.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,9 @@ namespace vix::commands
11821182
return exec_status(cmd) == 0;
11831183
}
11841184

1185-
void extract_archive_or_throw(const fs::path &archive, const fs::path &extractDir, const std::string &os)
1185+
void extract_archive_or_throw(
1186+
const fs::path &archive,
1187+
const fs::path &extractDir)
11861188
{
11871189
std::error_code ec;
11881190
fs::create_directories(extractDir, ec);
@@ -1794,7 +1796,7 @@ namespace vix::commands
17941796
if (!opt.jsonOut)
17951797
vix::cli::util::info_line(std::cout, "extracting...");
17961798

1797-
extract_archive_or_throw(archive, extractDir, os);
1799+
extract_archive_or_throw(archive, extractDir);
17981800

17991801
const std::string binName =
18001802
#ifdef _WIN32

src/commands/check/CheckFlow.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,18 @@ namespace vix::commands::CheckCommand::detail
120120
if (i + 1 < args.size())
121121
o.preset = args[++i];
122122
}
123-
else if (auto v = take_attached_value(a, "--preset="))
123+
else if (auto preset_value = take_attached_value(a, "--preset="))
124124
{
125-
o.preset = *v;
125+
o.preset = *preset_value;
126126
}
127127
else if (a == "-j" || a == "--jobs")
128128
{
129129
if (i + 1 < args.size())
130130
o.jobs = parse_int_or_default(args[++i], 0);
131131
}
132-
else if (auto v = take_attached_value(a, "--jobs="))
132+
else if (auto jobs_value = take_attached_value(a, "--jobs="))
133133
{
134-
o.jobs = parse_int_or_default(*v, 0);
134+
o.jobs = parse_int_or_default(*jobs_value, 0);
135135
}
136136
else if (a == "--quiet" || a == "-q")
137137
{
@@ -150,13 +150,13 @@ namespace vix::commands::CheckCommand::detail
150150
if (i + 1 < args.size())
151151
o.logLevel = args[++i];
152152
}
153-
else if (auto v = take_attached_value(a, "--log-level="))
153+
else if (auto log_level_value = take_attached_value(a, "--log-level="))
154154
{
155-
o.logLevel = *v;
155+
o.logLevel = *log_level_value;
156156
}
157-
else if (auto v = take_attached_value(a, "--loglevel="))
157+
else if (auto loglevel_value = take_attached_value(a, "--loglevel="))
158158
{
159-
o.logLevel = *v;
159+
o.logLevel = *loglevel_value;
160160
}
161161
else if (a == "--san")
162162
{
@@ -175,27 +175,27 @@ namespace vix::commands::CheckCommand::detail
175175
if (i + 1 < args.size())
176176
o.buildPreset = args[++i];
177177
}
178-
else if (auto v = take_attached_value(a, "--build-preset="))
178+
else if (auto build_preset_value = take_attached_value(a, "--build-preset="))
179179
{
180-
o.buildPreset = *v;
180+
o.buildPreset = *build_preset_value;
181181
}
182182
else if (a == "--ctest-preset")
183183
{
184184
if (i + 1 < args.size())
185185
o.ctestPreset = args[++i];
186186
}
187-
else if (auto v = take_attached_value(a, "--ctest-preset="))
187+
else if (auto ctest_preset_value = take_attached_value(a, "--ctest-preset="))
188188
{
189-
o.ctestPreset = *v;
189+
o.ctestPreset = *ctest_preset_value;
190190
}
191191
else if (a == "--ctest-arg")
192192
{
193193
if (i + 1 < args.size())
194194
o.ctestArgs.push_back(args[++i]);
195195
}
196-
else if (auto v = take_attached_value(a, "--ctest-arg="))
196+
else if (auto ctest_arg_value = take_attached_value(a, "--ctest-arg="))
197197
{
198-
o.ctestArgs.push_back(*v);
198+
o.ctestArgs.push_back(*ctest_arg_value);
199199
}
200200
else if (a == "--run")
201201
{
@@ -206,9 +206,9 @@ namespace vix::commands::CheckCommand::detail
206206
if (i + 1 < args.size())
207207
o.runTimeoutSec = parse_non_negative_int_or_default(args[++i], 0);
208208
}
209-
else if (auto v = take_attached_value(a, "--run-timeout="))
209+
else if (auto run_timeout_value = take_attached_value(a, "--run-timeout="))
210210
{
211-
o.runTimeoutSec = parse_non_negative_int_or_default(*v, 0);
211+
o.runTimeoutSec = parse_non_negative_int_or_default(*run_timeout_value, 0);
212212
}
213213
else if (!a.empty() && a != "--" && !is_option(a))
214214
{
@@ -220,8 +220,8 @@ namespace vix::commands::CheckCommand::detail
220220
}
221221
}
222222

223-
if (auto d = pick_dir_opt_local(args))
224-
o.dir = *d;
223+
if (auto dir_value = pick_dir_opt_local(args))
224+
o.dir = *dir_value;
225225

226226
if (o.enableUbsanOnly)
227227
o.enableSanitizers = false;

src/commands/run/detail/ScriptCMake.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -380,34 +380,6 @@ namespace vix::commands::RunCommand::detail
380380
return alias;
381381
}
382382

383-
static std::vector<std::string> extract_dep_aliases_from_include_dirs(
384-
const std::vector<std::string> &includeDirs)
385-
{
386-
std::vector<std::string> aliases;
387-
388-
for (const auto &d : includeDirs)
389-
{
390-
const std::string marker = "/.vix/deps/";
391-
const auto pos = d.find(marker);
392-
if (pos == std::string::npos)
393-
continue;
394-
395-
std::string tail = d.substr(pos + marker.size());
396-
const auto slash = tail.find('/');
397-
if (slash == std::string::npos)
398-
continue;
399-
400-
std::string pkg = tail.substr(0, slash);
401-
std::replace(pkg.begin(), pkg.end(), '.', '/');
402-
403-
aliases.push_back(dep_id_to_cmake_alias(pkg));
404-
}
405-
406-
std::sort(aliases.begin(), aliases.end());
407-
aliases.erase(std::unique(aliases.begin(), aliases.end()), aliases.end());
408-
return aliases;
409-
}
410-
411383
static std::vector<std::string> load_ordered_packages_from_lock(const fs::path &lockPath)
412384
{
413385
std::vector<std::string> ordered;

0 commit comments

Comments
 (0)