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
e05d94ec
Commit
e05d94ec
authored
7 years ago
by
Michael Davis
Browse files
Options
Downloads
Patches
Plain Diff
[cta_frontend] Parses command line options
parent
f196d8ad
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cmdline/CtaAdminCmd.cpp
+20
-1
20 additions, 1 deletion
cmdline/CtaAdminCmd.cpp
cmdline/CtaAdminCmd.hpp
+5
-0
5 additions, 0 deletions
cmdline/CtaAdminCmd.hpp
cmdline/CtaAdminCmdParse.hpp
+24
-7
24 additions, 7 deletions
cmdline/CtaAdminCmdParse.hpp
with
49 additions
and
8 deletions
cmdline/CtaAdminCmd.cpp
+
20
−
1
View file @
e05d94ec
...
...
@@ -91,19 +91,38 @@ void CtaAdminCmd::parseOptions(int start, int argc, const char *const *const arg
{
for
(
int
i
=
start
;
i
<
argc
;
++
i
)
{
int
opt_num
=
i
-
start
;
cmd_val_t
::
const_iterator
opt_it
;
// Scan options for a match
for
(
opt_it
=
options
.
begin
();
opt_it
!=
options
.
end
();
++
opt_it
)
{
// Special case of OPT_CMD type has an implicit key
if
(
opt_num
--
==
0
&&
opt_it
->
is_cmd
())
break
;
if
(
*
opt_it
==
argv
[
i
])
break
;
}
if
(
opt_it
==
options
.
end
())
throwUsage
(
std
::
string
(
"Invalid option: "
)
+
argv
[
i
]);
if
(
opt_it
==
options
.
end
())
{
throwUsage
(
std
::
string
(
"Invalid option: "
)
+
argv
[
i
]);
}
if
((
i
+=
opt_it
->
num_params
())
==
argc
)
{
throwUsage
(
std
::
string
(
argv
[
i
-
1
])
+
" expects a parameter"
);
}
addOption
(
opt_it
->
get_key
(),
argv
[
i
]);
}
}
void
CtaAdminCmd
::
addOption
(
const
std
::
string
&
key
,
const
std
::
string
&
value
)
{
std
::
cout
<<
"Setting "
<<
key
<<
" = "
<<
value
<<
std
::
endl
;
}
void
CtaAdminCmd
::
throwUsage
(
const
std
::
string
&
error_txt
)
const
{
std
::
stringstream
help
;
...
...
This diff is collapsed.
Click to expand it.
cmdline/CtaAdminCmd.hpp
+
5
−
0
View file @
e05d94ec
...
...
@@ -40,6 +40,11 @@ private:
*/
void
parseOptions
(
int
start
,
int
argc
,
const
char
*
const
*
const
argv
,
const
cmd_val_t
&
options
);
/*!
* Add a valid option to the protocol buffer
*/
void
addOption
(
const
std
::
string
&
key
,
const
std
::
string
&
value
);
/*!
* Throw an exception with usage help
*/
...
...
This diff is collapsed.
Click to expand it.
cmdline/CtaAdminCmdParse.hpp
+
24
−
7
View file @
e05d94ec
...
...
@@ -58,6 +58,30 @@ public:
return
option
;
}
/*!
* Check if the option is a command.
*
* Commands take no key, only a value
*/
bool
is_cmd
()
const
{
return
m_type
==
OPT_CMD
;
}
/*!
* Check if the supplied key matches the option
*/
bool
operator
==
(
const
std
::
string
&
option
)
const
{
return
option
==
m_short_opt
||
option
==
m_long_opt
;
}
/*!
* Return the key for this option
*/
const
std
::
string
&
get_key
()
const
{
return
m_lookup_key
;
}
/*!
* 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 per-option help string
*/
...
...
@@ -69,13 +93,6 @@ 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