Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dCache
cta
Commits
f196d8ad
Commit
f196d8ad
authored
7 years ago
by
Michael Davis
Browse files
Options
Downloads
Patches
Plain Diff
[cta_frontend] Finds the option list for the selected command/subcommand
parent
3831e227
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cmdline/CtaAdminCmd.cpp
+43
-17
43 additions, 17 deletions
cmdline/CtaAdminCmd.cpp
cmdline/CtaAdminCmd.hpp
+10
-5
10 additions, 5 deletions
cmdline/CtaAdminCmd.hpp
cmdline/CtaAdminCmdParse.hpp
+8
-1
8 additions, 1 deletion
cmdline/CtaAdminCmdParse.hpp
with
61 additions
and
23 deletions
cmdline/CtaAdminCmd.cpp
+
43
−
17
View file @
f196d8ad
...
...
@@ -20,7 +20,6 @@
#include
<sstream>
#include
<iostream>
#include
"CtaAdminCmdParse.hpp"
#include
"CtaAdminCmd.hpp"
#include
"XrdSsiPbDebug.hpp"
...
...
@@ -52,7 +51,9 @@ CtaAdminCmd::CtaAdminCmd(int argc, const char *const *const argv) :
// Parse the subcommand
if
(
cmdHelp
.
at
(
admincmd
.
cmd
()).
has_subcommand
())
bool
has_subcommand
=
cmdHelp
.
at
(
admincmd
.
cmd
()).
has_subcommand
();
if
(
has_subcommand
)
{
subcmdLookup_t
::
const_iterator
subcmd_it
;
...
...
@@ -63,28 +64,60 @@ CtaAdminCmd::CtaAdminCmd(int argc, const char *const *const argv) :
}
}
#if 0
// Tokenize the command
// Parse the options
auto
option_list_it
=
cmdOptions
.
find
(
cmd_key_t
{
admincmd
.
cmd
(),
admincmd
.
subcmd
()
});
if
(
option_list_it
==
cmdOptions
.
end
())
{
throwUsage
();
}
parseOptions
(
has_subcommand
?
3
:
2
,
argc
,
argv
,
option_list_it
->
second
);
}
void
CtaAdminCmd
::
send
()
const
{
// Validate the Protocol Buffer
// Send the Protocol Buffer
XrdSsiPb
::
OutputJsonString
(
std
::
cout
,
&
m_request
.
admincmd
());
}
for(int i = 1; i < argc; ++i)
void
CtaAdminCmd
::
parseOptions
(
int
start
,
int
argc
,
const
char
*
const
*
const
argv
,
const
cmd_val_t
&
options
)
{
for
(
int
i
=
start
;
i
<
argc
;
++
i
)
{
m_requestTokens.push_back(argv[i]);
cmd_val_t
::
const_iterator
opt_it
;
// Scan options for a match
for
(
opt_it
=
options
.
begin
();
opt_it
!=
options
.
end
();
++
opt_it
)
{
if
(
*
opt_it
==
argv
[
i
])
break
;
}
if
(
opt_it
==
options
.
end
())
throwUsage
(
std
::
string
(
"Invalid option: "
)
+
argv
[
i
]);
}
#endif
}
void
CtaAdminCmd
::
throwUsage
(
)
void
CtaAdminCmd
::
throwUsage
(
const
std
::
string
&
error_txt
)
const
{
std
::
stringstream
help
;
const
auto
&
admincmd
=
m_request
.
admincmd
().
cmd
();
if
(
error_txt
!=
""
)
{
help
<<
error_txt
<<
std
::
endl
;
}
if
(
admincmd
==
AdminCmd
::
CMD_NONE
)
{
// Command has not been set: show generic help
help
<<
"CTA Admin commands:"
<<
std
::
endl
<<
std
::
endl
help
<<
"CTA Admin commands:"
<<
std
::
endl
<<
std
::
endl
<<
"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
;
...
...
@@ -103,13 +136,6 @@ void CtaAdminCmd::throwUsage()
throw
std
::
runtime_error
(
help
.
str
());
}
void
CtaAdminCmd
::
send
()
{
XrdSsiPb
::
OutputJsonString
(
std
::
cout
,
&
m_request
.
admincmd
());
}
}}
// namespace cta::admin
...
...
@@ -126,7 +152,7 @@ int main(int argc, const char **argv)
using
namespace
cta
::
admin
;
try
{
//
Tokenize and p
arse the command line arguments
//
P
arse the command line arguments
CtaAdminCmd
cmd
(
argc
,
argv
);
// Send the protocol buffer
...
...
This diff is collapsed.
Click to expand it.
cmdline/CtaAdminCmd.hpp
+
10
−
5
View file @
f196d8ad
...
...
@@ -19,7 +19,7 @@
#pragma once
#include
"CtaAdminCmdParse.hpp"
namespace
cta
{
namespace
admin
{
...
...
@@ -32,19 +32,24 @@ public:
/*!
* Send the protocol buffer across the XRootD SSI transport
*/
void
send
();
void
send
()
const
;
private:
/*!
* Parse the options for a specific command/subcommand
*/
void
parseOptions
(
int
start
,
int
argc
,
const
char
*
const
*
const
argv
,
const
cmd_val_t
&
options
);
/*!
* Throw an exception with usage help
*/
void
throwUsage
(
)
;
void
throwUsage
(
const
std
::
string
&
error_txt
=
""
)
const
;
/*
* Member variables
*/
std
::
string
m_execname
;
//!< Executable name of this program
cta
::
xrd
::
Request
m_request
;
//!< Protocol Buffer for the command and parameters
std
::
string
m_execname
;
//!< Executable name of this program
cta
::
xrd
::
Request
m_request
;
//!< Protocol Buffer for the command and parameters
};
}}
// namespace cta::admin
...
...
This diff is collapsed.
Click to expand it.
cmdline/CtaAdminCmdParse.hpp
+
8
−
1
View file @
f196d8ad
...
...
@@ -61,7 +61,7 @@ public:
/*!
* Return per-option help string
*/
std
::
string
help
()
{
std
::
string
help
()
const
{
std
::
string
help
=
m_is_optional
?
" ["
:
" "
;
help
+=
(
m_type
==
OPT_CMD
)
?
""
:
m_long_opt
+
'/'
+
m_short_opt
;
help
+=
m_help_txt
;
...
...
@@ -69,6 +69,13 @@ public:
return
help
;
}
/*!
* Check for a matching option string
*/
bool
operator
==
(
const
std
::
string
&
option
)
const
{
return
option
==
m_short_opt
||
option
==
m_long_opt
;
}
private
:
option_t
m_type
;
//!< Option type
std
::
string
m_lookup_key
;
//!< Key to map option string to Protocol Buffer enum
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment