Skip to content

Commit 092b869

Browse files
authored
add default argument (optional params)
1 parent 59042f8 commit 092b869

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/flexistack/flexistack.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -585,17 +585,18 @@ def _load(_directory, _parser, _subparser):
585585
_act = next((item.value.value for item in parg.value.keywords if item.arg == 'action'), None)
586586
_des = next((item.value.value for item in parg.value.keywords if item.arg == 'help'), None)
587587
_narg = next((item.value.value for item in parg.value.keywords if item.arg == 'nargs'), None)
588+
_df = next((item.value.value for item in parg.value.keywords if item.arg == 'default'), None)
588589
_tp = next((eval(item.value.id) for item in parg.value.keywords if item.arg == 'type'), None)
589590
if len(v) == 2:
590-
if _act == 'store_true':
591-
__subparser.add_argument(v[0],v[1],action=_act,help=_des)
591+
if _act == 'store_true' or _act == 'store_false':
592+
__subparser.add_argument(v[0],v[1],default=_df,action=_act,help=_des)
592593
else:
593-
__subparser.add_argument(v[0],v[1],type=_tp,nargs=_narg,action=_act,help=_des)
594+
__subparser.add_argument(v[0],v[1],default=_df,type=_tp,nargs=_narg,action=_act,help=_des)
594595
elif len(v) == 1:
595-
if _act == 'store_true':
596-
__subparser.add_argument(v[0],action=_act,help=_des)
596+
if _act == 'store_true' or _act == 'store_false':
597+
__subparser.add_argument(v[0],default=_df,action=_act,help=_des)
597598
else:
598-
__subparser.add_argument(v[0],type=_tp,nargs=_narg,action=_act,help=_des)
599+
__subparser.add_argument(v[0],default=_df,type=_tp,nargs=_narg,action=_act,help=_des)
599600
self.dprint(3, "cmp", "Loaded!")
600601
found = True
601602
break

0 commit comments

Comments
 (0)