Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cyber-sandbox-creator
Manage
Activity
Members
Labels
Plan
Issues
10
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
MUNI-KYPO-CSC
cyber-sandbox-creator
Commits
866a6950
Commit
866a6950
authored
5 years ago
by
Attila Farkas
Browse files
Options
Downloads
Patches
Plain Diff
parsing input arguments with argparse
parent
fa428078
No related branches found
No related tags found
1 merge request
!7
Resolve Refactoring
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/input_argument_parser.py
+12
-17
12 additions, 17 deletions
modules/input_argument_parser.py
with
12 additions
and
17 deletions
modules/input_argument_parser.py
+
12
−
17
View file @
866a6950
"""
This module contains functions to parse input arguments.
"""
"""
This module contains functions to parse input arguments.
"""
import
argparse
def
parse_input_args
(
argv
,
flags
):
def
parse_input_args
(
argv
,
flags
):
"""
"""
Parses the given input arguments for input file name and flags.
Parses the given input arguments for input file name and flags.
...
@@ -7,27 +9,20 @@ def parse_input_args(argv, flags):
...
@@ -7,27 +9,20 @@ def parse_input_args(argv, flags):
:param argv: input arguments (list of strings)
:param argv: input arguments (list of strings)
:param flags: dictionary to write the parsed flags
:param flags: dictionary to write the parsed flags
:returns: name of the input file
:returns: name of the input file
:raise AttributeError: invalid number of args or unknown flag
"""
"""
input_file_name
=
None
input_file_name
=
None
parser
=
argparse
.
ArgumentParser
()
# TODO implement parsing args using an external module
parser
.
add_argument
(
"
definition_file
"
,
help
=
"
path to the input yaml definition
"
)
parser
.
add_argument
(
"
--ansible_local
"
,
help
=
"
uses ansible_local for provisioning instead of ansible
"
,
action
=
"
store_true
"
)
parser
.
add_argument
(
"
--verbose_vagrant
"
,
help
=
"
sets verbose output for vagrant
"
,
action
=
"
store_true
"
)
parser
.
add_argument
(
"
--border_router
"
,
help
=
"
creates a border router with connection to all routers
"
,
action
=
"
store_true
"
)
args
=
parser
.
parse_args
()
if
len
(
argv
)
==
3
:
input_file_name
=
args
.
definition_file
if
str
(
argv
[
1
])
==
"
-l
"
:
flags
[
"
ansible_local
"
]
=
args
.
ansible_local
flags
[
"
ansible_local
"
]
=
True
flags
[
"
verbose_vagrant
"
]
=
args
.
verbose_vagrant
input_file_name
=
str
(
argv
[
2
])
flags
[
"
border_router
"
]
=
args
.
border_router
elif
str
(
argv
[
2
])
==
"
-l
"
:
flags
[
"
ansible_local
"
]
=
True
input_file_name
=
str
(
argv
[
1
])
else
:
print
(
"
Error: Expecting a yml file and optionally a flag -l.
"
)
raise
AttributeError
elif
len
(
argv
)
==
2
:
input_file_name
=
str
(
argv
[
1
])
else
:
print
(
"
Error: Expecting a yml file and optionally a flag -l.
"
)
raise
AttributeError
return
input_file_name
return
input_file_name
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