Skip to content

Commit 52a946e

Browse files
committed
fix(cli): achieve zero warnings across CLI module
2 parents ef626ea + f690b9b commit 52a946e

File tree

14 files changed

+78
-106
lines changed

14 files changed

+78
-106
lines changed

src/CLI.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,25 +102,25 @@ namespace vix
102102
return std::nullopt;
103103
}
104104

105-
static int levenshtein_distance(const std::string &a, const std::string &b)
105+
static std::size_t levenshtein_distance(const std::string &a, const std::string &b)
106106
{
107-
const size_t m = a.size();
108-
const size_t n = b.size();
107+
const std::size_t m = a.size();
108+
const std::size_t n = b.size();
109109

110-
std::vector<int> prev(n + 1), curr(n + 1);
110+
std::vector<std::size_t> prev(n + 1), curr(n + 1);
111111

112-
for (size_t j = 0; j <= n; ++j)
112+
for (std::size_t j = 0; j <= n; ++j)
113113
prev[j] = j;
114114

115-
for (size_t i = 1; i <= m; ++i)
115+
for (std::size_t i = 1; i <= m; ++i)
116116
{
117117
curr[0] = i;
118-
for (size_t j = 1; j <= n; ++j)
118+
for (std::size_t j = 1; j <= n; ++j)
119119
{
120-
int cost = (a[i - 1] == b[j - 1]) ? 0 : 1;
120+
const std::size_t cost = (a[i - 1] == b[j - 1]) ? 0u : 1u;
121121

122-
curr[j] = std::min({prev[j] + 1,
123-
curr[j - 1] + 1,
122+
curr[j] = std::min({prev[j] + 1u,
123+
curr[j - 1] + 1u,
124124
prev[j - 1] + cost});
125125
}
126126
prev = curr;
@@ -133,12 +133,12 @@ namespace vix
133133
const std::string &input,
134134
const std::unordered_map<std::string, vix::cli::dispatch::Entry> &entries)
135135
{
136-
int bestScore = INT_MAX;
136+
std::size_t bestScore = std::numeric_limits<std::size_t>::max();
137137
std::string best;
138138

139139
for (const auto &[name, _] : entries)
140140
{
141-
int d = levenshtein_distance(input, name);
141+
const std::size_t d = levenshtein_distance(input, name);
142142

143143
if (d < bestScore)
144144
{

src/commands/NewCommand.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -834,11 +834,6 @@ int main()
834834
std::cout.flush();
835835
}
836836

837-
static std::string gray_tip(const std::string &s)
838-
{
839-
return std::string(GRAY) + s + RESET;
840-
}
841-
842837
static MultiSelectResult menu_multiselect_features()
843838
{
844839
MultiSelectResult res{};

src/commands/PublishCommand.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ namespace vix::commands
150150
out << j.dump(2) << "\n";
151151
}
152152

153+
#if defined(_WIN32)
153154
static std::string join_for_log(
154155
const std::vector<std::string> &args)
155156
{
@@ -191,6 +192,7 @@ namespace vix::commands
191192

192193
return out.str();
193194
}
195+
#endif
194196

195197
struct ProcessResult
196198
{
@@ -433,11 +435,10 @@ namespace vix::commands
433435
if (pid == 0)
434436
{
435437
// child
436-
if (cwd)
438+
if (chdir(cwd->c_str()) != 0)
437439
{
438-
(void)chdir(cwd->c_str());
440+
_exit(127);
439441
}
440-
441442
dup2(outPipe[1], STDOUT_FILENO);
442443
dup2(errPipe[1], STDERR_FILENO);
443444

src/commands/TaskCommand.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,10 @@ namespace vix::commands
11901190
return 0;
11911191
}
11921192

1193-
ExecuteContext ctx{registry};
1193+
ExecuteContext ctx{
1194+
.registry = registry,
1195+
.done = {},
1196+
.visiting = {}};
11941197

11951198
if (args.empty())
11961199
{

src/commands/UnpublishCommand.cpp

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ namespace vix::commands
7070
static std::string iso_utc_now_compact()
7171
{
7272
using namespace std::chrono;
73+
7374
const auto now = system_clock::now();
7475
const std::time_t t = system_clock::to_time_t(now);
7576

@@ -80,11 +81,18 @@ namespace vix::commands
8081
gmtime_r(&t, &tm);
8182
#endif
8283

83-
char buf[32]{0};
84-
std::snprintf(buf, sizeof(buf), "%04d%02d%02dT%02d%02d%02dZ",
85-
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
86-
tm.tm_hour, tm.tm_min, tm.tm_sec);
87-
return std::string(buf);
84+
std::ostringstream oss;
85+
86+
oss << std::setw(4) << std::setfill('0') << (tm.tm_year + 1900)
87+
<< std::setw(2) << std::setfill('0') << (tm.tm_mon + 1)
88+
<< std::setw(2) << std::setfill('0') << tm.tm_mday
89+
<< "T"
90+
<< std::setw(2) << std::setfill('0') << tm.tm_hour
91+
<< std::setw(2) << std::setfill('0') << tm.tm_min
92+
<< std::setw(2) << std::setfill('0') << tm.tm_sec
93+
<< "Z";
94+
95+
return oss.str();
8896
}
8997

9098
static std::string home_dir()
@@ -123,17 +131,20 @@ namespace vix::commands
123131
return fs::exists(dir / ".git", ec);
124132
}
125133

126-
std::string join_for_log(const std::vector<std::string> &args)
134+
#if defined(_WIN32)
135+
static std::string join_for_log(
136+
const std::vector<std::string> &args)
127137
{
128138
std::ostringstream out;
129139

130140
for (std::size_t i = 0; i < args.size(); ++i)
131141
{
132142
if (i > 0)
143+
{
133144
out << ' ';
145+
}
134146

135147
const std::string &arg = args[i];
136-
137148
const bool needsQuotes =
138149
arg.find(' ') != std::string::npos ||
139150
arg.find('\t') != std::string::npos ||
@@ -149,15 +160,20 @@ namespace vix::commands
149160
for (char c : arg)
150161
{
151162
if (c == '"')
163+
{
152164
out << "\\\"";
165+
}
153166
else
167+
{
154168
out << c;
169+
}
155170
}
156171
out << '"';
157172
}
158173

159174
return out.str();
160175
}
176+
#endif
161177

162178
/* =========================
163179
Process runner (no system)
@@ -403,7 +419,12 @@ namespace vix::commands
403419
if (pid == 0)
404420
{
405421
if (cwd)
406-
(void)chdir(cwd->c_str());
422+
{
423+
if (chdir(cwd->c_str()) != 0)
424+
{
425+
_exit(127);
426+
}
427+
}
407428

408429
dup2(outPipe[1], STDOUT_FILENO);
409430
dup2(errPipe[1], STDERR_FILENO);

src/commands/UpgradeCommand.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include <system_error>
3434
#include <vector>
3535
#include <ctime>
36+
#include <iomanip>
37+
#include <sstream>
3638

3739
#ifndef _WIN32
3840
#include <unistd.h>
@@ -224,19 +226,21 @@ namespace vix::commands
224226
gmtime_r(&t, &tm);
225227
#endif
226228

227-
char buf[32];
228-
std::snprintf(
229-
buf,
230-
sizeof(buf),
231-
"%04d-%02d-%02dT%02d:%02d:%02dZ",
232-
tm.tm_year + 1900,
233-
tm.tm_mon + 1,
234-
tm.tm_mday,
235-
tm.tm_hour,
236-
tm.tm_min,
237-
tm.tm_sec);
238-
239-
return std::string(buf);
229+
std::ostringstream oss;
230+
oss << std::setw(4) << std::setfill('0') << (tm.tm_year + 1900)
231+
<< "-"
232+
<< std::setw(2) << std::setfill('0') << (tm.tm_mon + 1)
233+
<< "-"
234+
<< std::setw(2) << std::setfill('0') << tm.tm_mday
235+
<< "T"
236+
<< std::setw(2) << std::setfill('0') << tm.tm_hour
237+
<< ":"
238+
<< std::setw(2) << std::setfill('0') << tm.tm_min
239+
<< ":"
240+
<< std::setw(2) << std::setfill('0') << tm.tm_sec
241+
<< "Z";
242+
243+
return oss.str();
240244
}
241245

242246
std::string home_dir()

src/commands/make/MakeDispatcher.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,6 @@ namespace vix::cli::make
3636
return result;
3737
}
3838

39-
[[nodiscard]] MakeResult make_not_implemented_result(
40-
const MakeContext &ctx,
41-
const std::string &what)
42-
{
43-
MakeResult result;
44-
result.ok = false;
45-
result.error = what + " generator is not implemented yet.";
46-
result.notes.push_back("kind: " + std::string(to_string(ctx.kind)));
47-
result.notes.push_back("name: " + ctx.name);
48-
result.notes.push_back("namespace: " +
49-
(ctx.name_space.empty() ? std::string("(none)")
50-
: ctx.name_space));
51-
return result;
52-
}
53-
5439
[[nodiscard]] bool requires_name(MakeKind kind) noexcept
5540
{
5641
switch (kind)

src/commands/make/generators/ClassGenerator.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,6 @@ namespace vix::cli::make::generators
6262
return trim(std::move(s));
6363
}
6464

65-
[[nodiscard]] std::string capitalize_first(std::string s)
66-
{
67-
if (!s.empty())
68-
{
69-
s.front() = static_cast<char>(
70-
std::toupper(static_cast<unsigned char>(s.front())));
71-
}
72-
73-
return s;
74-
}
75-
7665
[[nodiscard]] std::string member_name(const std::string &field_name)
7766
{
7867
return field_name + "_";

src/commands/make/generators/LambdaGenerator.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,6 @@ namespace vix::cli::make::generators
8181
out << header_postamble();
8282
return out.str();
8383
}
84-
85-
[[nodiscard]] std::string build_preview(const MakeContext &ctx,
86-
const fs::path &header_path)
87-
{
88-
std::ostringstream out;
89-
out << "kind: lambda\n";
90-
out << "name: " << ctx.name << "\n";
91-
out << "namespace: "
92-
<< (ctx.name_space.empty() ? "(none)" : ctx.name_space) << "\n";
93-
out << "header: " << header_path.string() << "\n";
94-
out << "mode: header-only\n";
95-
return out.str();
96-
}
9784
} // namespace
9885

9986
MakeResult generate_lambda(const MakeContext &ctx)

src/commands/make/generators/TestGenerator.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ namespace vix::cli::make::generators
5454
return out;
5555
}
5656

57-
[[nodiscard]] std::string build_test_content(const MakeContext &ctx,
58-
const std::string &suite_name,
59-
const std::string &test_name,
60-
const fs::path &file_path)
57+
[[nodiscard]] std::string build_test_content(
58+
[[maybe_unused]] const MakeContext &ctx,
59+
const std::string &suite_name,
60+
const std::string &test_name,
61+
const fs::path &file_path)
6162
{
6263
std::ostringstream out;
6364
out << doxygen_file_header(file_path.filename().string());

0 commit comments

Comments
 (0)