GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/publish/main.cc
Date: 2024-04-28 02:33:07
Exec Total Coverage
Lines: 0 54 0.0%
Branches: 0 182 0.0%

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