CernVM-FS
2.13.0
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
main.cc
Go to the documentation of this file.
1
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_transaction.h
"
21
#include "
publish/cmd_zpipe.h
"
22
#include "
publish/command.h
"
23
#include "
publish/except.h
"
24
#include "
util/logging.h
"
25
26
using namespace
std;
// NOLINT
27
28
29
static
void
PrintVersion
() {
30
LogCvmfs
(
kLogCvmfs
,
kLogStdout
,
"CernVM-FS Server Tool %s"
, CVMFS_VERSION);
31
}
32
33
static
void
Usage
(
const
std::string &progname,
34
const
publish::CommandList
&clist) {
35
LogCvmfs
(
kLogCvmfs
,
kLogStdout
,
36
"CernVM-FS Server Tool %s\n"
37
"NOTE: This utility is for CernVM-FS internal use only for the time "
38
"being!"
39
"\n\n"
40
"Usage:\n"
41
"------\n"
42
" %s COMMAND [options] <parameters>\n\n"
43
"Supported Commands\n"
44
"-------------------\n"
,
45
CVMFS_VERSION, progname.c_str());
46
const
vector<publish::Command *> commands = clist.
commands
();
47
48
string::size_type max_len = 0;
49
for
(
unsigned
i = 0; i < commands.size(); ++i) {
50
if
(commands[i]->IsHidden())
51
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())
57
continue
;
58
LogCvmfs
(
kLogCvmfs
,
kLogStdout
|
kLogNoLinebreak
,
" %s"
,
59
commands[i]->GetName().c_str());
60
for
(
unsigned
p = commands[i]->GetName().length(); p < max_len; ++p)
61
LogCvmfs
(
kLogCvmfs
,
kLogStdout
|
kLogNoLinebreak
,
" "
);
62
LogCvmfs
(
kLogCvmfs
,
kLogStdout
,
" %s"
, commands[i]->GetBrief().c_str());
63
}
64
65
LogCvmfs
(
kLogCvmfs
,
kLogStdout
|
kLogNoLinebreak
,
"\n"
);
66
}
67
68
69
int
main
(
int
argc,
char
**argv) {
70
publish::CommandList
commands;
71
commands.
TakeCommand
(
new
publish::CmdMkfs
());
72
commands.
TakeCommand
(
new
publish::CmdTransaction
());
73
commands.
TakeCommand
(
new
publish::CmdCommit
());
74
commands.
TakeCommand
(
new
publish::CmdAbort
());
75
commands.
TakeCommand
(
new
publish::CmdEnter
());
76
commands.
TakeCommand
(
new
publish::CmdInfo
());
77
commands.
TakeCommand
(
new
publish::CmdDiff
());
78
commands.
TakeCommand
(
new
publish::CmdHelp
(&commands));
79
commands.
TakeCommand
(
new
publish::CmdZpipe
());
80
commands.
TakeCommand
(
new
publish::CmdHash
());
81
commands.
TakeCommand
(
new
publish::CmdLsof
());
82
83
if
(argc < 2) {
84
Usage
(argv[0], commands);
85
return
1;
86
}
87
if
((
string
(argv[1]) ==
"--help"
) || (
string
(argv[1]) ==
"-h"
)) {
88
Usage
(argv[0], commands);
89
return
0;
90
}
91
if
((
string
(argv[1]) ==
"--version"
) || (
string
(argv[1]) ==
"-v"
)) {
92
PrintVersion
();
93
return
0;
94
}
95
96
publish::Command
*command = commands.
Find
(argv[1]);
97
if
(command == NULL) {
98
LogCvmfs
(
kLogCvmfs
,
kLogStderr
,
"unknown command: %s"
, argv[1]);
99
Usage
(argv[0], commands);
100
return
1;
101
}
102
103
try
{
104
const
publish::Command::Options
options = command->
ParseOptions
(argc, argv);
105
return
command->
Main
(options);
106
}
catch
(
const
publish::EPublish
&e) {
107
if
(e.
failure
() ==
publish::EPublish::kFailInvocation
) {
108
LogCvmfs
(
kLogCvmfs
,
kLogStderr
,
"Invocation error: %s"
, e.
msg
().c_str());
109
}
else
if
(e.
failure
() ==
publish::EPublish::kFailMissingDependency
) {
110
LogCvmfs
(
kLogCvmfs
,
kLogStderr
,
"Missing dependency: %s"
,
111
e.
msg
().c_str());
112
}
else
if
(e.
failure
() ==
publish::EPublish::kFailPermission
) {
113
LogCvmfs
(
kLogCvmfs
,
kLogStderr
,
"Permission error: %s"
, e.
msg
().c_str());
114
}
else
{
115
LogCvmfs
(
kLogCvmfs
,
kLogStderr
,
"(unexpected termination) %s"
, e.what());
116
}
117
return
1;
118
}
119
}
publish::CmdInfo
Definition:
cmd_info.h:14
except.h
cmd_commit.h
publish::CmdDiff
Definition:
cmd_diff.h:15
cmd_info.h
command.h
cmd_abort.h
publish::Command::Options
Definition:
command.h:104
cmd_zpipe.h
Usage
static void Usage(const char *progname)
Definition:
cvmfs_cache_null.cc:276
PrintVersion
static void PrintVersion()
Definition:
main.cc:29
cmd_mkfs.h
publish::CmdHash
Definition:
cmd_hash.h:14
publish::EPublish::msg
std::string msg() const
Definition:
except.h:45
publish::CommandList::TakeCommand
void TakeCommand(Command *command)
Definition:
command.cc:136
publish::CommandList::Find
Command * Find(const std::string &name)
Definition:
command.cc:125
publish::EPublish::kFailMissingDependency
Definition:
except.h:34
kLogNoLinebreak
Definition:
logging_internal.h:59
logging.h
publish::CommandList::commands
const std::vector< Command * > & commands() const
Definition:
command.h:194
main
int main()
Definition:
helper_allow.cc:16
kLogStdout
Definition:
logging_internal.h:23
kLogStderr
Definition:
logging_internal.h:24
publish::EPublish
Definition:
except.h:13
publish::CommandList
Definition:
command.h:188
publish::Command::ParseOptions
Options ParseOptions(int argc, char **argv)
Definition:
command.cc:33
publish::CmdLsof
Definition:
cmd_lsof.h:14
publish::CmdMkfs
Definition:
cmd_mkfs.h:14
cmd_help.h
publish::CmdEnter
Definition:
cmd_enter.h:18
publish::CmdHelp
Definition:
cmd_help.h:14
publish::CmdAbort
Definition:
cmd_abort.h:15
publish::EPublish::kFailPermission
Definition:
except.h:22
publish::CmdTransaction
Definition:
cmd_transaction.h:15
publish::Command::Main
virtual int Main(const Options &options)=0
publish::EPublish::kFailInvocation
Definition:
except.h:21
cmd_hash.h
publish::CmdZpipe
Definition:
cmd_zpipe.h:14
kLogCvmfs
Definition:
logging_internal.h:80
publish::EPublish::failure
EFailures failure() const
Definition:
except.h:44
cmd_transaction.h
cmd_diff.h
publish::Command
Definition:
command.h:20
cmd_enter.h
cmd_lsof.h
publish::CmdCommit
Definition:
cmd_commit.h:15
LogCvmfs
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)
Definition:
logging.cc:545
cvmfs
cvmfs
publish
main.cc
Generated on Sun Jun 15 2025 02:21:13 for CernVM-FS by
1.8.5