Skip to content

Commit 9c356cd

Browse files
author
Dmitry Malakhov
committed
run cabin fmt on project
1 parent 4c1eb85 commit 9c356cd

18 files changed

+138
-210
lines changed

src/Algos.hpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,11 @@ levDistance(const std::string_view lhs, const std::string_view rhs) noexcept {
5656
for (std::size_t i = 1; i <= lhsSize; ++i) {
5757
for (std::size_t j = 1; j <= rhsSize; ++j) {
5858
const std::size_t substCost = lhs[i - 1] == rhs[j - 1] ? 0 : 1;
59-
dist[i][j] = std::min(
60-
{
61-
dist[i - 1][j] + 1, // deletion
62-
dist[i][j - 1] + 1, // insertion
63-
dist[i - 1][j - 1] + substCost // substitution
64-
}
65-
);
59+
dist[i][j] = std::min({
60+
dist[i - 1][j] + 1, // deletion
61+
dist[i][j - 1] + 1, // insertion
62+
dist[i - 1][j - 1] + substCost // substitution
63+
});
6664
}
6765
}
6866

src/Builder/Compiler.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,8 @@ Compiler::makeCompileCmd(
223223
}
224224

225225
Command
226-
Compiler::makeMMCmd(
227-
const CompilerOpts& opts, const std::string& sourceFile
228-
) const {
226+
Compiler::makeMMCmd(const CompilerOpts& opts, const std::string& sourceFile)
227+
const {
229228
return Command(cxx)
230229
.addArgs(opts.cFlags.others)
231230
.addArgs(opts.cFlags.macros)

src/Builder/Project.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ Project::Project(
103103
} else {
104104
compilerOpts.cFlags.macros.emplace_back("NDEBUG", "");
105105
}
106-
compilerOpts.cFlags.others.emplace_back(
107-
fmt::format("-O{}", profile.optLevel)
106+
compilerOpts.cFlags.others.emplace_back(fmt::format("-O{}", profile.optLevel)
108107
);
109108
if (profile.lto) {
110109
compilerOpts.cFlags.others.emplace_back("-flto");

src/Cli.cc

+10-16
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,8 @@ formatOpts(
108108
}
109109

110110
std::string
111-
Opt::format(
112-
const std::size_t maxShortSize, std::size_t maxOffset
113-
) const noexcept {
111+
Opt::format(const std::size_t maxShortSize, std::size_t maxOffset)
112+
const noexcept {
114113
std::string option;
115114
if (!shortName.empty()) {
116115
option += Bold(Cyan(shortName)).toStr();
@@ -657,9 +656,8 @@ Cli::calcMaxOffset(const std::size_t maxShortSize) const noexcept {
657656
}
658657

659658
std::string
660-
Cli::formatAllSubcmds(
661-
const bool showHidden, std::size_t maxOffset
662-
) const noexcept {
659+
Cli::formatAllSubcmds(const bool showHidden, std::size_t maxOffset)
660+
const noexcept {
663661
for (const auto& [name, cmd] : subcmds) {
664662
if (!showHidden && cmd.isHidden) {
665663
// Hidden command should not affect maxOffset if `showHidden` is false.
@@ -706,11 +704,9 @@ Cli::formatCmdHelp() const noexcept {
706704
str += formatHeader("Commands:");
707705
str += formatAllSubcmds(false, maxOffset);
708706
str += Subcmd{ "..." }
709-
.setDesc(
710-
fmt::format(
711-
"See all commands with {}", Bold(Cyan("--list")).toStr()
712-
)
713-
)
707+
.setDesc(fmt::format(
708+
"See all commands with {}", Bold(Cyan("--list")).toStr()
709+
))
714710
.format(maxOffset);
715711
str += '\n';
716712
str += fmt::format(
@@ -765,11 +761,9 @@ getCli() noexcept {
765761
.addOpt(Opt{ "-vv" }.setShort("-vv"))
766762
.addOpt(Opt{ "--jobs" }.setShort("-j").setPlaceholder("<NUM>"))
767763
.addSubcmd(Subcmd{ "run" }.setShort("r"))
768-
.addSubcmd(
769-
Subcmd{ "build" }.addOpt(
770-
Opt{ "--target" }.setShort("-t").setPlaceholder("<TARGET>")
771-
)
772-
);
764+
.addSubcmd(Subcmd{ "build" }.addOpt(
765+
Opt{ "--target" }.setShort("-t").setPlaceholder("<TARGET>")
766+
));
773767
return cli;
774768
}
775769

src/Cli.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ class Subcmd : public CliBase<Subcmd>, public ShortAndHidden<Subcmd> {
196196
Subcmd& addOpt(Opt opt) noexcept;
197197
Subcmd& setMainFn(std::function<MainFn> mainFn) noexcept;
198198
[[nodiscard]] AnyhowErr noSuchArg(std::string_view arg) const;
199-
[[nodiscard]] static AnyhowErr
200-
missingOptArgumentFor(std::string_view arg) noexcept;
199+
[[nodiscard]] static AnyhowErr missingOptArgumentFor(std::string_view arg
200+
) noexcept;
201201

202202
private:
203203
constexpr Subcmd& setCmdName(std::string_view cmdName) noexcept {
@@ -253,8 +253,8 @@ class Cli : public CliBase<Cli> {
253253
Result<void> parseArgs(int argc, char* argv[]) const noexcept;
254254

255255
// NOTE: This is public only for tests
256-
Result<std::vector<std::string>>
257-
expandOpts(std::span<const char* const> args) const noexcept;
256+
Result<std::vector<std::string>> expandOpts(std::span<const char* const> args
257+
) const noexcept;
258258

259259
private:
260260
Result<void> parseArgs(CliArgsView args) const noexcept;

src/Cmd/Add.cc

+13-21
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,23 @@ static Result<void> addMain(CliArgsView args);
2222
const Subcmd ADD_CMD =
2323
Subcmd{ "add" }
2424
.setDesc("Add dependencies to cabin.toml")
25-
.setArg(
26-
Arg{ "args" }
27-
.setDesc("Dependencies to add")
28-
.setRequired(true)
29-
.setVariadic(true)
30-
)
25+
.setArg(Arg{ "args" }
26+
.setDesc("Dependencies to add")
27+
.setRequired(true)
28+
.setVariadic(true))
3129
.addOpt(Opt{ "--sys" }.setDesc("Use system dependency"))
32-
.addOpt(
33-
Opt{ "--version" }.setDesc(
34-
"Dependency version (Only used with system-dependencies)"
35-
)
36-
)
30+
.addOpt(Opt{ "--version" }.setDesc(
31+
"Dependency version (Only used with system-dependencies)"
32+
))
3733
.addOpt(
3834
Opt{ "--tag" }.setDesc("Specify a git tag").setPlaceholder("<TAG>")
3935
)
40-
.addOpt(
41-
Opt{ "--rev" }
42-
.setDesc("Specify a git revision")
43-
.setPlaceholder("<REVISION>")
44-
)
45-
.addOpt(
46-
Opt{ "--branch" }
47-
.setDesc("Specify a branch of the git repository")
48-
.setPlaceholder("<BRANCH_NAME>")
49-
)
36+
.addOpt(Opt{ "--rev" }
37+
.setDesc("Specify a git revision")
38+
.setPlaceholder("<REVISION>"))
39+
.addOpt(Opt{ "--branch" }
40+
.setDesc("Specify a branch of the git repository")
41+
.setPlaceholder("<BRANCH_NAME>"))
5042
.setMainFn(addMain);
5143

5244
static Result<void>

src/Cmd/Build.cc

+3-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ const Subcmd BUILD_CMD =
2929
.setShort("b")
3030
.setDesc("Compile a local package and all of its dependencies")
3131
.addOpt(OPT_RELEASE)
32-
.addOpt(
33-
Opt{ "--compdb" }.setDesc(
34-
"Generate compilation database instead of building"
35-
)
36-
)
32+
.addOpt(Opt{ "--compdb" }.setDesc(
33+
"Generate compilation database instead of building"
34+
))
3735
.addOpt(OPT_JOBS)
3836
.setMainFn(buildMain);
3937

src/Cmd/Clean.cc

+4-6
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ static Result<void> cleanMain(CliArgsView args) noexcept;
1616
const Subcmd CLEAN_CMD = //
1717
Subcmd{ "clean" }
1818
.setDesc("Remove the built directory")
19-
.addOpt(
20-
Opt{ "--profile" }
21-
.setShort("-p")
22-
.setDesc("Disable parallel builds")
23-
.setPlaceholder("<PROFILE>")
24-
)
19+
.addOpt(Opt{ "--profile" }
20+
.setShort("-p")
21+
.setDesc("Disable parallel builds")
22+
.setPlaceholder("<PROFILE>"))
2523
.setMainFn(cleanMain);
2624

2725
static Result<void>

src/Cmd/Fmt.cc

+3-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ const Subcmd FMT_CMD =
2626
Subcmd{ "fmt" }
2727
.setDesc("Format codes using clang-format")
2828
.addOpt(Opt{ "--check" }.setDesc("Run clang-format in check mode"))
29-
.addOpt(
30-
Opt{ "--exclude" }
31-
.setDesc("Exclude files from formatting")
32-
.setPlaceholder("<FILE>")
33-
)
29+
.addOpt(Opt{ "--exclude" }
30+
.setDesc("Exclude files from formatting")
31+
.setPlaceholder("<FILE>"))
3432
.setMainFn(fmtMain);
3533

3634
static std::vector<std::string>

src/Cmd/Lint.cc

+3-5
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ static Result<void> lintMain(CliArgsView args);
2121

2222
const Subcmd LINT_CMD = Subcmd{ "lint" }
2323
.setDesc("Lint codes using cpplint")
24-
.addOpt(
25-
Opt{ "--exclude" }
26-
.setDesc("Exclude files from linting")
27-
.setPlaceholder("<FILE>")
28-
)
24+
.addOpt(Opt{ "--exclude" }
25+
.setDesc("Exclude files from linting")
26+
.setPlaceholder("<FILE>"))
2927
.setMainFn(lintMain);
3028

3129
struct LintArgs {

src/Cmd/Remove.cc

+4-6
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@ static Result<void> removeMain(CliArgsView args);
2020
const Subcmd REMOVE_CMD = //
2121
Subcmd{ "remove" }
2222
.setDesc("Remove dependencies from cabin.toml")
23-
.setArg(
24-
Arg{ "deps" }
25-
.setDesc("Dependencies to remove")
26-
.setRequired(true)
27-
.setVariadic(true)
28-
)
23+
.setArg(Arg{ "deps" }
24+
.setDesc("Dependencies to remove")
25+
.setRequired(true)
26+
.setVariadic(true))
2927
.setMainFn(removeMain);
3028

3129
static Result<void>

src/Cmd/Run.cc

+11-12
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,17 @@ namespace cabin {
2424

2525
static Result<void> runMain(CliArgsView args);
2626

27-
const Subcmd RUN_CMD = Subcmd{ "run" }
28-
.setShort("r")
29-
.setDesc("Build and execute src/main.cc")
30-
.addOpt(OPT_RELEASE)
31-
.addOpt(OPT_JOBS)
32-
.setArg(
33-
Arg{ "args" }
34-
.setDesc("Arguments passed to the program")
35-
.setVariadic(true)
36-
.setRequired(false)
37-
)
38-
.setMainFn(runMain);
27+
const Subcmd RUN_CMD =
28+
Subcmd{ "run" }
29+
.setShort("r")
30+
.setDesc("Build and execute src/main.cc")
31+
.addOpt(OPT_RELEASE)
32+
.addOpt(OPT_JOBS)
33+
.setArg(Arg{ "args" }
34+
.setDesc("Arguments passed to the program")
35+
.setVariadic(true)
36+
.setRequired(false))
37+
.setMainFn(runMain);
3938

4039
static Result<void>
4140
runMain(const CliArgsView args) {

src/Cmd/Search.cc

+8-12
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,14 @@ static Result<void> searchMain(CliArgsView args);
2020
const Subcmd SEARCH_CMD =
2121
Subcmd{ "search" }
2222
.setDesc("Search for packages in the registry")
23-
.addOpt(
24-
Opt{ "--per-page" }
25-
.setDesc("Number of results to show per page")
26-
.setPlaceholder("<NUM>")
27-
.setDefault("10")
28-
)
29-
.addOpt(
30-
Opt{ "--page" }
31-
.setDesc("Page number of results to show")
32-
.setPlaceholder("<NUM>")
33-
.setDefault("1")
34-
)
23+
.addOpt(Opt{ "--per-page" }
24+
.setDesc("Number of results to show per page")
25+
.setPlaceholder("<NUM>")
26+
.setDefault("10"))
27+
.addOpt(Opt{ "--page" }
28+
.setDesc("Page number of results to show")
29+
.setPlaceholder("<NUM>")
30+
.setDefault("1"))
3531
.setArg(Arg{ "name" })
3632
.setMainFn(searchMain);
3733

src/Command.cc

+5-9
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,9 @@ Child::waitWithOutput() const noexcept {
171171
if (waitpid(pid, &status, 0) == -1) {
172172
Bail("waitpid() failed");
173173
}
174-
return Ok(
175-
CommandOutput{ .exitStatus = ExitStatus{ status },
176-
.stdOut = stdOutOutput,
177-
.stdErr = stdErrOutput }
178-
);
174+
return Ok(CommandOutput{ .exitStatus = ExitStatus{ status },
175+
.stdOut = stdOutOutput,
176+
.stdErr = stdErrOutput });
179177
}
180178

181179
Result<Child>
@@ -269,10 +267,8 @@ Command::spawn() const noexcept {
269267
}
270268

271269
// Return the Child object with appropriate file descriptors
272-
return Ok(
273-
Child{ pid, stdOutConfig == IOConfig::Piped ? stdOutPipe[0] : -1,
274-
stdErrConfig == IOConfig::Piped ? stdErrPipe[0] : -1 }
275-
);
270+
return Ok(Child{ pid, stdOutConfig == IOConfig::Piped ? stdOutPipe[0] : -1,
271+
stdErrConfig == IOConfig::Piped ? stdErrPipe[0] : -1 });
276272
}
277273
}
278274

0 commit comments

Comments
 (0)