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
87d44b94
Commit
87d44b94
authored
7 years ago
by
Michael Davis
Browse files
Options
Downloads
Patches
Plain Diff
[cta_admin] Validates command line options
parent
ae0d3a80
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
+6
-1
6 additions, 1 deletion
cmdline/CtaAdminCmd.cpp
cmdline/CtaAdminCmdParse.cpp
+33
-0
33 additions, 0 deletions
cmdline/CtaAdminCmdParse.cpp
cmdline/CtaAdminCmdParse.hpp
+10
-3
10 additions, 3 deletions
cmdline/CtaAdminCmdParse.hpp
with
49 additions
and
4 deletions
cmdline/CtaAdminCmd.cpp
+
6
−
1
View file @
87d44b94
...
...
@@ -79,7 +79,12 @@ CtaAdminCmd::CtaAdminCmd(int argc, const char *const *const argv) :
void
CtaAdminCmd
::
send
()
const
{
// Validate the Protocol Buffer
validateOptions
(
m_request
.
admincmd
());
try
{
validateCommand
(
m_request
.
admincmd
());
}
catch
(
std
::
runtime_error
&
ex
)
{
throwUsage
(
ex
.
what
());
}
// Send the Protocol Buffer
XrdSsiPb
::
OutputJsonString
(
std
::
cout
,
&
m_request
.
admincmd
());
...
...
This diff is collapsed.
Click to expand it.
cmdline/CtaAdminCmdParse.cpp
+
33
−
0
View file @
87d44b94
...
...
@@ -79,5 +79,38 @@ std::string CmdHelp::help() const {
return
help
;
}
void
validateCommand
(
const
cta
::
admin
::
AdminCmd
&
admincmd
)
{
// Get the option list for this command
auto
option_list_it
=
cmdOptions
.
find
(
cmd_key_t
{
admincmd
.
cmd
(),
admincmd
.
subcmd
()
});
if
(
option_list_it
==
cmdOptions
.
end
())
{
throw
std
::
runtime_error
(
"Invalid command/subcommand"
);
}
// Verify that the compulsory options exist
for
(
auto
option_it
=
option_list_it
->
second
.
begin
();
option_it
!=
option_list_it
->
second
.
end
();
++
option_it
)
{
if
(
!
option_it
->
is_optional
())
{
switch
(
option_it
->
get_type
())
{
case
Option
::
OPT_CMD
:
case
Option
::
OPT_STR
:
admincmd
.
option_str
()
case
Option
::
OPT_FLAG
:
case
Option
::
OPT_BOOL
:
admincmd
.
option_bool
()
case
Option
::
OPT_UINT
:
admincmd
.
option_uint64
()
}
}
}
}
}}
// namespace cta::admin
This diff is collapsed.
Click to expand it.
cmdline/CtaAdminCmdParse.hpp
+
10
−
3
View file @
87d44b94
...
...
@@ -70,15 +70,20 @@ public:
*/
option_t
get_type
()
const
{
return
m_type
;
}
/*!
* Return the number of parameters expected after this option
*/
int
num_params
()
const
{
return
m_type
==
OPT_CMD
||
m_type
==
OPT_FLAG
?
0
:
1
;
}
/*!
* Return the key for this option
*/
const
std
::
string
&
get_key
()
const
{
return
m_lookup_key
;
}
/*!
* Return
the number of parameters expected after th
is option
* Return
whether the option
is option
al
*/
int
num_params
()
const
{
return
m_
type
==
OPT_CMD
||
m_type
==
OPT_FLAG
?
0
:
1
;
}
bool
is_optional
()
const
{
return
m_
is_optional
;
}
/*!
* Return per-option help string
...
...
@@ -497,7 +502,9 @@ const std::map<cmd_key_t, cmd_val_t> cmdOptions = {
/*!
* Validate that all required command line options are present
*
* Throws a std::runtime_error if the command is invalid
*/
void
validate
Options
(
const
cta
::
admin
::
AdminCmd
&
admin
_
cmd
);
void
validate
Command
(
const
cta
::
admin
::
AdminCmd
&
admincmd
);
}}
// namespace cta::admin
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