Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
isgphys
python
Commits
4c685c00
Commit
4c685c00
authored
4 years ago
by
Sven Mäder
Browse files
Options
Downloads
Patches
Plain Diff
Allow extendable simple argparser
parent
e56065d0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/isg/argparser.py
+30
-8
30 additions, 8 deletions
lib/isg/argparser.py
with
30 additions
and
8 deletions
lib/isg/argparser.py
+
30
−
8
View file @
4c685c00
...
...
@@ -2,9 +2,10 @@
import
argparse
def
simple
(
description
,
arg
=
None
,
arg_help
=
''
,
opts
=
dict
(),
noopts
=
dict
()):
def
extendable
(
description
,
arg
=
None
,
arg_help
=
''
,
opts
=
dict
(),
noopts
=
dict
()):
"""
Get
cmd argument with
simplified argparser
Get
extendable
simplified argparser
"""
parser
=
argparse
.
ArgumentParser
(
add_help
=
False
,
description
=
description
)
...
...
@@ -15,18 +16,39 @@ def simple(description, arg=None, arg_help='', opts=dict(), noopts=dict()):
for
k
,
v
in
opts
.
items
():
if
isinstance
(
v
,
list
):
v
=
'
,
'
.
join
(
v
)
parser
.
add_argument
(
'
-
'
+
k
[:
1
],
'
--
'
+
k
,
dest
=
k
,
action
=
'
store_const
'
,
const
=
True
,
help
=
'
Show
'
+
v
)
try
:
parser
.
add_argument
(
'
-
'
+
k
[:
1
],
'
--
'
+
k
,
dest
=
k
,
action
=
'
store_const
'
,
const
=
True
,
help
=
'
Show
'
+
v
)
except
argparse
.
ArgumentError
:
parser
.
add_argument
(
'
--
'
+
k
,
dest
=
k
,
action
=
'
store_const
'
,
const
=
True
,
help
=
'
Show
'
+
v
)
for
k
,
v
in
noopts
.
items
():
if
isinstance
(
v
,
list
):
v
=
'
,
'
.
join
(
v
)
parser
.
add_argument
(
'
-
'
+
k
[
3
:
4
].
upper
(),
'
--
'
+
k
,
dest
=
k
,
action
=
'
store_const
'
,
const
=
True
,
help
=
'
Hide
'
+
v
)
try
:
parser
.
add_argument
(
'
-
'
+
k
[
3
:
4
].
upper
(),
'
--
'
+
k
,
dest
=
k
,
action
=
'
store_const
'
,
const
=
True
,
help
=
'
Hide
'
+
v
)
except
argparse
.
ArgumentError
:
parser
.
add_argument
(
'
--
'
+
k
,
dest
=
k
,
action
=
'
store_const
'
,
const
=
True
,
help
=
'
Hide
'
+
v
)
parser
.
add_argument
(
'
--help
'
,
action
=
'
help
'
,
help
=
'
Show this help message and exit
'
)
return
parser
def
simple
(
description
,
arg
=
None
,
arg_help
=
''
,
opts
=
dict
(),
noopts
=
dict
()):
"""
Get cmd argument with simplified argparser
"""
parser
=
extendable
(
description
,
arg
=
arg
,
arg_help
=
arg_help
,
opts
=
opts
,
noopts
=
noopts
)
return
vars
(
parser
.
parse_args
())
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