GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/publish/cmd_help.cc
Date: 2026-10-04 02:40:33
Exec Total Coverage
Lines: 0 48 0.0%
Branches: 0 140 0.0%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5
6 #include "cmd_help.h"
7
8 #include <algorithm>
9 #include <string>
10 #include <vector>
11
12 #include "publish/except.h"
13 #include "util/logging.h"
14 #include "util/string.h"
15
16 using namespace std; // NOLINT
17
18 namespace publish {
19
20 ✗ int CmdHelp::Main(const Options &options) {
21 ✗ Command *cmd = commands_->Find(options.plain_args()[0].value_str);
22 ✗ if (cmd == NULL) {
23 ✗ LogCvmfs(kLogCvmfs, kLogStderr, "No help for '%s'",
24 ✗ options.plain_args()[0].value_str.c_str());
25 ✗ return 1;
26 }
27
28 ✗ cmd->progname_ = progname();
29 ✗ LogCvmfs(kLogCvmfs, kLogStdout, "\nHelp for '%s'", cmd->GetName().c_str());
30 ✗ for (unsigned i = 0; i < cmd->GetName().length() + 11; ++i)
31 ✗ LogCvmfs(kLogCvmfs, kLogStdout | kLogNoLinebreak, "=");
32 ✗ LogCvmfs(kLogCvmfs, kLogStdout | kLogNoLinebreak, "\n");
33 ✗ LogCvmfs(kLogCvmfs, kLogStdout, "%s\n", cmd->GetDescription().c_str());
34
35 ✗ LogCvmfs(kLogCvmfs, kLogStdout, "Usage:");
36 ✗ LogCvmfs(kLogCvmfs, kLogStdout, "------");
37 ✗ LogCvmfs(kLogCvmfs, kLogStdout, " %s %s %s\n", progname().c_str(),
38 ✗ cmd->GetName().c_str(), cmd->GetUsage().c_str());
39
40 ✗ const std::string examples = cmd->GetExamples();
41 ✗ if (!examples.empty()) {
42 ✗ LogCvmfs(kLogCvmfs, kLogStdout, "Examples:");
43 ✗ LogCvmfs(kLogCvmfs, kLogStdout, "---------");
44 ✗ std::vector<std::string> ex_lines = SplitString(examples, '\n');
45 ✗ for (unsigned i = 0; i < ex_lines.size() - 1; ++i) {
46 ✗ LogCvmfs(kLogCvmfs, kLogStdout, " [%d] %s", i + 1, ex_lines[i].c_str());
47 }
48 ✗ LogCvmfs(kLogCvmfs, kLogStdout | kLogNoLinebreak, "\n");
49 }
50
51 ✗ ParameterList params = cmd->GetParams();
52 ✗ if (params.empty())
53 ✗ return 0;
54
55 ✗ LogCvmfs(kLogCvmfs, kLogStdout, "Options:");
56 ✗ LogCvmfs(kLogCvmfs, kLogStdout, "--------");
57 ✗ string::size_type max_len = 0;
58 ✗ for (unsigned i = 0; i < params.size(); ++i) {
59 ✗ string::size_type l = params[i].key.length();
60 ✗ if (!params[i].is_switch) {
61 ✗ l += 3 + params[i].arg_name.length();
62 }
63 ✗ max_len = std::max(max_len, l);
64 }
65 ✗ for (unsigned i = 0; i < params.size(); ++i) {
66 ✗ LogCvmfs(
67 kLogCvmfs, kLogStdout | kLogNoLinebreak, " -%c, --%s%s",
68 ✗ params[i].short_key, params[i].key.c_str(),
69 ✗ params[i].is_switch ? "" : (" <" + params[i].arg_name + ">").c_str());
70 ✗ unsigned l = params[i].key.length();
71 ✗ if (!params[i].is_switch)
72 ✗ l += 3 + params[i].arg_name.length();
73 ✗ for (unsigned p = l; p < max_len; ++p)
74 ✗ LogCvmfs(kLogCvmfs, kLogStdout | kLogNoLinebreak, " ");
75 ✗ LogCvmfs(kLogCvmfs, kLogStdout, " %s%s", params[i].description.c_str(),
76 ✗ params[i].is_optional ? "" : " [mandatory]");
77 }
78 ✗ LogCvmfs(kLogCvmfs, kLogStdout | kLogNoLinebreak, "\n");
79
80 ✗ return 0;
81 }
82
83 } // namespace publish
84