GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/publish/main.cc
Date: 2026-06-28 02:36:10
Exec Total Coverage
Lines: 0 57 0.0%
Branches: 0 186 0.0%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5
6 #include <algorithm>
7 #include <cstdlib>
8 #include <string>
9 #include <vector>
10
11 #include "publish/cmd_abort.h"
12 #include "publish/cmd_commit.h"
13 #include "publish/cmd_diff.h"
14 #include "publish/cmd_enter.h"
15 #include "publish/cmd_hash.h"
16 #include "publish/cmd_help.h"
17 #include "publish/cmd_info.h"
18 #include "publish/cmd_lsof.h"
19 #include "publish/cmd_mkfs.h"
20 #include "publish/cmd_tag.h"
21 #include "publish/cmd_transaction.h"
22 #include "publish/cmd_zpipe.h"
23 #include "publish/command.h"
24 #include "publish/except.h"
25 #include "util/logging.h"
26
27 using namespace std; // NOLINT
28
29
30 static void PrintVersion() {
31 LogCvmfs(kLogCvmfs, kLogStdout, "CernVM-FS Server Tool %s", CVMFS_VERSION);
32 }
33
34 static void Usage(const std::string &progname,
35 const publish::CommandList &clist) {
36 LogCvmfs(kLogCvmfs, kLogStdout,
37 "CernVM-FS Server Tool %s\n"
38 "NOTE: This utility is for CernVM-FS internal use only for the time "
39 "being!"
40 "\n\n"
41 "Usage:\n"
42 "------\n"
43 " %s COMMAND [options] <parameters>\n\n"
44 "Supported Commands\n"
45 "-------------------\n",
46 CVMFS_VERSION, progname.c_str());
47 const vector<publish::Command *> commands = clist.commands();
48
49 string::size_type max_len = 0;
50 for (unsigned i = 0; i < commands.size(); ++i) {
51 if (commands[i]->IsHidden())
52 continue;
53 max_len = std::max(commands[i]->GetName().length(), max_len);
54 }
55
56 for (unsigned i = 0; i < commands.size(); ++i) {
57 if (commands[i]->IsHidden())
58 continue;
59 LogCvmfs(kLogCvmfs, kLogStdout | kLogNoLinebreak, " %s",
60 commands[i]->GetName().c_str());
61 for (unsigned p = commands[i]->GetName().length(); p < max_len; ++p)
62 LogCvmfs(kLogCvmfs, kLogStdout | kLogNoLinebreak, " ");
63 LogCvmfs(kLogCvmfs, kLogStdout, " %s", commands[i]->GetBrief().c_str());
64 }
65
66 LogCvmfs(kLogCvmfs, kLogStdout | kLogNoLinebreak, "\n");
67 }
68
69
70 int main(int argc, char **argv) {
71 publish::CommandList commands;
72 commands.TakeCommand(new publish::CmdMkfs());
73 commands.TakeCommand(new publish::CmdTransaction());
74 commands.TakeCommand(new publish::CmdCommit());
75 commands.TakeCommand(new publish::CmdAbort());
76 commands.TakeCommand(new publish::CmdEnter());
77 commands.TakeCommand(new publish::CmdInfo());
78 commands.TakeCommand(new publish::CmdDiff());
79 commands.TakeCommand(new publish::CmdHelp(&commands));
80 commands.TakeCommand(new publish::CmdZpipe());
81 commands.TakeCommand(new publish::CmdHash());
82 commands.TakeCommand(new publish::CmdLsof());
83 commands.TakeCommand(new publish::CmdTag());
84
85 if (argc < 2) {
86 Usage(argv[0], commands);
87 return 1;
88 }
89 if ((string(argv[1]) == "--help") || (string(argv[1]) == "-h")) {
90 Usage(argv[0], commands);
91 return 0;
92 }
93 if ((string(argv[1]) == "--version") || (string(argv[1]) == "-v")) {
94 PrintVersion();
95 return 0;
96 }
97
98 publish::Command *command = commands.Find(argv[1]);
99 if (command == NULL) {
100 LogCvmfs(kLogCvmfs, kLogStderr, "unknown command: %s", argv[1]);
101 Usage(argv[0], commands);
102 return 1;
103 }
104
105 try {
106 const publish::Command::Options options = command->ParseOptions(argc, argv);
107 return command->Main(options);
108 } catch (const publish::EPublish &e) {
109 if (e.failure() == publish::EPublish::kFailInvocation) {
110 LogCvmfs(kLogCvmfs, kLogStderr, "Invocation error: %s", e.msg().c_str());
111 } else if (e.failure() == publish::EPublish::kFailMissingDependency) {
112 LogCvmfs(kLogCvmfs, kLogStderr, "Missing dependency: %s",
113 e.msg().c_str());
114 } else if (e.failure() == publish::EPublish::kFailPermission) {
115 LogCvmfs(kLogCvmfs, kLogStderr, "Permission error: %s", e.msg().c_str());
116 } else {
117 LogCvmfs(kLogCvmfs, kLogStderr, "(unexpected termination) %s", e.what());
118 }
119 return 1;
120 }
121 }
122