MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / runFormatTool

Function runFormatTool

Tools/SC-format.cpp:64–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62 return processLimiter.close();
63}
64Result runFormatTool(Tool::Arguments& arguments)
65{
66 SmallString<256> clangFormat;
67 static constexpr StringView wantedVersion = "20.1.8";
68 if (not Tools::findSystemClangFormat(arguments.console, wantedVersion, clangFormat))
69 {
70 StringView additionalArgs[1];
71 Tool::Arguments args = arguments;
72 args.tool = "packages";
73 args.action = "install";
74 additionalArgs[0] = "clang";
75 args.arguments = {additionalArgs};
76 // If no system installed clang-format (matching version 20.1.8) has been found, we install a local copy.
77 Tools::Package clangPackage;
78 SC_TRY(runPackageTool(args, &clangPackage));
79 SC_TRY(StringBuilder::format(clangFormat, "{}/bin/clang-format", clangPackage.installDirectoryLink));
80 }
81 arguments.console.print("Using: {}\n", clangFormat);
82
83 if (arguments.action == "execute")
84 {
85 return Tools::formatSourceFiles(Tools::FormatSources::Execute, clangFormat.view(),
86 arguments.libraryDirectory.view());
87 }
88 else if (arguments.action == "check")
89 {
90 return Tools::formatSourceFiles(Tools::FormatSources::Check, clangFormat.view(),
91 arguments.libraryDirectory.view());
92 }
93 else
94 {
95 return Result::Error("SC-format unknown action (supported \"execute\" or \"check\")");
96 }
97}
98#if !defined(SC_TOOLS_COMPILED_SEPARATELY) && !defined(SC_TOOLS_IMPORT)
99StringView Tool::getToolName() { return "SC-format"; }
100StringView Tool::getDefaultAction() { return "execute"; }

Callers 2

SupportToolsTestMethod · 0.85
runToolMethod · 0.85

Calls 5

formatSourceFilesFunction · 0.85
printMethod · 0.80
formatFunction · 0.70
ErrorEnum · 0.50
viewMethod · 0.45

Tested by 1

SupportToolsTestMethod · 0.68