Skip to content
Snippets Groups Projects
Commit a72b0801 authored by Michael Davis's avatar Michael Davis
Browse files

[cta_frontend] Parses commands and subcommands

parent 925b28ae
No related branches found
No related tags found
No related merge requests found
......@@ -50,30 +50,20 @@ CtaAdminCmd::CtaAdminCmd(int argc, const char *const *const argv) :
admincmd.set_cmd(cmd_it->second);
}
#if 0
// Parse the subcommand
int nextarg = 2;
int &num_subcmds = cmd_it->second.sub_cmd.size();
bool has_subcommand = cmdHelp.at(admincmd.cmd()).sub_cmd.size() > 0;
if(num_subcmds > 0)
if(has_subcommand)
{
if(argc < 3) throwUsage();
subCmdLookup_t::const_iterator subcmd_it;
int i;
for(i = 0; i < num_subcmds; ++i)
{
if(argv[2] == cmd_it->second.sub_cmd.at(i))
{
admincmd.set_subcmd(subCmd.at(argv[2]));
break;
}
if(argc < 3 || (subcmd_it = subCmdLookup.find(argv[2])) == subCmdLookup.end()) {
throwUsage();
} else {
admincmd.set_subcmd(subcmd_it->second);
}
if(i == num_subcmds) throwUsage();
++nextarg;
}
#endif
#if 0
// Tokenize the command
......@@ -99,13 +89,13 @@ void CtaAdminCmd::throwUsage()
<< "For each command there is a short version and a long one. "
<< "Subcommands (add/ch/ls/rm/etc.) do not have short versions." << std::endl << std::endl;
for(auto lo_it = cmdHelp.begin(); lo_it != cmdHelp.end(); ++lo_it)
for(auto cmd_it = cmdHelp.begin(); cmd_it != cmdHelp.end(); ++cmd_it)
{
std::string cmd = lo_it->second.cmd_long + '/' + lo_it->second.cmd_short;
std::string cmd = cmd_it->second.cmd_long + '/' + cmd_it->second.cmd_short;
cmd.resize(25, ' ');
help << " " << m_execname << " " << cmd;
help << " " << m_execname << ' ' << cmd;
auto &sub_cmd = lo_it->second.sub_cmd;
auto &sub_cmd = cmd_it->second.sub_cmd;
for(auto sc_it = sub_cmd.begin(); sc_it != sub_cmd.end(); ++sc_it)
{
help << (sc_it == sub_cmd.begin() ? ' ' : '/') << *sc_it;
......@@ -117,7 +107,30 @@ void CtaAdminCmd::throwUsage()
{
// Show command-specific help
help << "hello" << std::endl;
auto &cmd_help = cmdHelp.at(m_request.admincmd().cmd());
help << m_execname << ' ' << cmd_help.cmd_short << '/' << cmd_help.cmd_long;
for(auto sc_it = cmd_help.sub_cmd.begin(); sc_it != cmd_help.sub_cmd.end(); ++sc_it)
{
help << (sc_it == cmd_help.sub_cmd.begin() ? ' ' : '/') << *sc_it;
}
if(cmd_help.help_str.size() > 0)
{
help << ' ' << cmd_help.help_str;
}
// Show per-option help
if(cmd_help.sub_cmd.size() > 0)
{
help << ':' << std::endl;
}
for(auto sc_it = cmd_help.sub_cmd.begin(); sc_it != cmd_help.sub_cmd.end(); ++sc_it)
{
help << '\t' << *sc_it << std::endl;
}
}
throw std::runtime_error(help.str());
......
......@@ -44,7 +44,6 @@ private:
* Member variables
*/
std::string m_execname; //!< Executable name of this program
std::vector<std::string> m_requestTokens; //!< The command line parameters represented as a vector of strings
cta::xrd::Request m_request; //!< Protocol Buffer for the command and parameters
};
......
......@@ -93,7 +93,8 @@ const subCmdLookup_t subCmdLookup = {
{ "up", AdminCmd::SUBCMD_UP },
{ "down", AdminCmd::SUBCMD_DOWN },
{ "read", AdminCmd::SUBCMD_READ },
{ "write", AdminCmd::SUBCMD_WRITE }
{ "write", AdminCmd::SUBCMD_WRITE },
{ "write_auto", AdminCmd::SUBCMD_WRITE_AUTO }
};
......@@ -120,20 +121,24 @@ const std::map<AdminCmd::Cmd, CmdHelp> cmdHelp = {
{ AdminCmd::CMD_ADMINHOST, { "adminhost", "ah", { "add", "ch", "rm", "ls" }, "" }},
{ AdminCmd::CMD_ARCHIVEFILE, { "archivefile", "af", { "ls" }, "" }},
{ AdminCmd::CMD_ARCHIVEROUTE, { "archiveroute", "ar", { "add", "ch", "rm", "ls" }, "" }},
{ AdminCmd::CMD_DRIVE, { "drive", "dr", { "up", "down", "ls" }, "" }},
{ AdminCmd::CMD_GROUPMOUNTRULE, { "groupmountrule", "gmr", { "add", "rm", "ls", "err" }, "" }},
{ AdminCmd::CMD_DRIVE, { "drive", "dr", { "up", "down", "ls" },
"(it is a synchronous command)" }},
{ AdminCmd::CMD_GROUPMOUNTRULE, { "groupmountrule", "gmr", { "add", "ch", "rm", "ls" }, "" }},
{ AdminCmd::CMD_LISTPENDINGARCHIVES, { "listpendingarchives", "lpa", { }, "" }},
{ AdminCmd::CMD_LISTPENDINGRETRIEVES, { "listpendingretrieves", "lpr", { }, "" }},
{ AdminCmd::CMD_LOGICALLIBRARY, { "logicallibrary", "ll", { "add", "ch", "rm", "ls" }, "" }},
{ AdminCmd::CMD_MOUNTPOLICY, { "mountpolicy", "mp", { "add", "ch", "rm", "ls" }, "" }},
{ AdminCmd::CMD_REPACK, { "repack", "re", { "add", "rm", "ls", "err" }, "" }},
{ AdminCmd::CMD_REQUESTERMOUNTRULE, { "requestermountrule", "rmr", { "add", "rm", "ls", "err" }, "" }},
{ AdminCmd::CMD_REQUESTERMOUNTRULE, { "requestermountrule", "rmr", { "add", "ch", "rm", "ls" }, "" }},
{ AdminCmd::CMD_SHOWQUEUES, { "showqueues", "sq", { }, "" }},
{ AdminCmd::CMD_SHRINK, { "shrink", "sh", { }, "" }},
{ AdminCmd::CMD_STORAGECLASS, { "storageclass", "sc", { "add", "ch", "rm", "ls" }, "" }},
{ AdminCmd::CMD_TAPE, { "tape", "ta", { "add", "ch", "rm", "reclaim", "ls", "label" }, "" }},
{ AdminCmd::CMD_TAPEPOOL, { "tapepool", "tp", { "add", "ch", "rm", "ls" }, "" }},
{ AdminCmd::CMD_TEST, { "test", "te", { "read", "write" }, "" }},
{ AdminCmd::CMD_TEST, { "test", "te", { "read", "write", "write_auto" },
"(to be run on an empty self-dedicated\n"
"drive; it is a synchronous command that returns performance stats and errors;\n"
"all locations are local to the tapeserver)" }},
{ AdminCmd::CMD_VERIFY, { "verify", "ve", { "add", "rm", "ls", "err" }, "" }}
};
......
......@@ -127,6 +127,7 @@ message AdminCmd {
SUBCMD_DOWN = 9;
SUBCMD_READ = 10;
SUBCMD_WRITE = 11;
SUBCMD_WRITE_AUTO = 12;
}
Cmd cmd = 1; //< The primary command
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment