Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Michiel Cottaar
fsl_mrs
Commits
2bdf7391
Commit
2bdf7391
authored
Apr 20, 2020
by
William Clarke
Browse files
Modifications to configargparse. Now accepts repeated arguments of lists.
parent
9623613d
Changes
2
Hide whitespace changes
Inline
Side-by-side
fsl_mrs/aux/configargparse.py
View file @
2bdf7391
...
...
@@ -164,10 +164,22 @@ class DefaultConfigFileParser(ConfigFileParser):
value
=
key_value_match
.
group
(
"value"
)
if
value
.
startswith
(
"["
)
and
value
.
endswith
(
"]"
):
# breakpoint()
# handle special case of lists
value
=
[
elem
.
strip
()
for
elem
in
value
[
1
:
-
1
].
split
(
","
)]
items
[
key
]
=
value
if
key
in
items
:
# If key is already in the dict then convert the value to a list and append
if
isinstance
(
items
[
key
],
list
):
if
isinstance
(
items
[
key
][
0
],
list
):
items
[
key
].
append
(
value
)
else
:
items
[
key
]
=
[
items
[
key
],
value
]
else
:
items
[
key
]
=
[
items
[
key
],
value
]
else
:
# Else - just add
items
[
key
]
=
value
continue
raise
ConfigFileParserException
(
"Unexpected line {} in {}: {}"
.
format
(
i
,
...
...
@@ -741,7 +753,7 @@ class ArgumentParser(argparse.ArgumentParser):
self
.
error
(
"Unexpected value for %s: '%s'. Expecting 'true', "
"'false', 'yes', 'no', '1' or '0'"
%
(
key
,
value
))
elif
isinstance
(
value
,
list
):
accepts_list
=
(
isinstance
(
action
,
argparse
.
_StoreAction
)
and
accepts_list
=
(
isinstance
(
action
,
(
argparse
.
_StoreAction
,
argparse
.
_AppendAction
)
)
and
action
.
nargs
in
(
'+'
,
'*'
))
or
(
isinstance
(
action
,
argparse
.
_StoreAction
)
and
isinstance
(
action
.
nargs
,
int
)
and
action
.
nargs
>
1
)
...
...
fsl_mrs/scripts/fsl_mrs
View file @
2bdf7391
...
...
@@ -101,7 +101,7 @@ def main():
# Parse command-line arguments
args
=
p
.
parse_args
()
breakpoint
()
# Output kickass splash screen
if
args
.
verbose
:
splash
(
logo
=
'mrs'
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment