Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
scriptconfig
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Utils
scriptconfig
Commits
482d3f4b
Commit
482d3f4b
authored
1 year ago
by
Jon Crall
Browse files
Options
Downloads
Patches
Plain Diff
Better handling of nested modal CLIs
parent
c2d5c715
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!27
Start branch for dev/0.7.10
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scriptconfig/modal.py
+38
-8
38 additions, 8 deletions
scriptconfig/modal.py
with
38 additions
and
8 deletions
scriptconfig/modal.py
+
38
−
8
View file @
482d3f4b
...
...
@@ -53,8 +53,8 @@ class MetaModalCLI(type):
final_subconfigs
.
extend
(
cls_subconfigs
)
# Helps make the class pickleable. Pretty hacky though.
for
k
in
attr_subconfigs
.
keys
():
namespace
.
pop
(
k
)
#
for k in attr_subconfigs.keys():
#
namespace.pop(k)
namespace
[
'
__subconfigs__
'
]
=
final_subconfigs
cls
=
super
().
__new__
(
mcls
,
name
,
bases
,
namespace
,
*
args
,
**
kwargs
)
...
...
@@ -216,6 +216,8 @@ class ModalCLI(metaclass=MetaModalCLI):
cmdinfo_list
=
[]
for
cli_cls
in
self
.
sub_clis
:
cmdname
=
getattr
(
cli_cls
,
'
__command__
'
,
None
)
if
cmdname
is
None
:
cmdname
=
cli_cls
.
__name__
if
cmdname
is
None
:
raise
ValueError
(
ub
.
paragraph
(
f
'''
...
...
@@ -240,10 +242,29 @@ class ModalCLI(metaclass=MetaModalCLI):
group
=
getattr
(
cli_cls
,
'
__group__
'
,
DEFAULT_GROUP
)
# group = 'FOO'
if
isinstance
(
cli_cls
,
ModalCLI
):
# print(f'cli_cls={cli_cls}')
# print(isinstance(cli_cls, ModalCLI))
# print('cli_cls.__bases__ = {}'.format(ub.urepr(cli_cls.__bases__, nl=1)))
# print('ModalCLI = {}'.format(ub.urepr(ModalCLI, nl=1)))
if
isinstance
(
cli_cls
,
ModalCLI
)
or
issubclass
(
cli_cls
,
ModalCLI
):
# Another modal layer
modal
=
cli_cls
from
scriptconfig
import
argparse_ext
# FIXME: ModalCLI needs a _parserkw method.
parserkw
.
update
(
# prog=self._prog,
description
=
self
.
description
,
# epilog=self._epilog,
# formatter_class=argparse.ArgumentDefaultsHelpFormatter,
# formatter_class=argparse.RawDescriptionHelpFormatter,
formatter_class
=
argparse_ext
.
RawDescriptionDefaultsHelpFormatter
,
# exit_on_error=False,
)
parserkw
[
'
help
'
]
=
parserkw
[
'
description
'
].
split
(
'
\n
'
)[
0
]
cmdinfo_list
.
append
({
'
is_modal
'
:
True
,
'
cmdname
'
:
cmdname
,
'
parserkw
'
:
parserkw
,
'
main_func
'
:
cli_cls
.
main
,
...
...
@@ -256,6 +277,7 @@ class ModalCLI(metaclass=MetaModalCLI):
parserkw
.
update
(
subconfig
.
_parserkw
())
parserkw
[
'
help
'
]
=
parserkw
[
'
description
'
].
split
(
'
\n
'
)[
0
]
cmdinfo_list
.
append
({
'
is_modal
'
:
False
,
'
cmdname
'
:
cmdname
,
'
parserkw
'
:
parserkw
,
'
main_func
'
:
cli_cls
.
main
,
...
...
@@ -274,7 +296,7 @@ class ModalCLI(metaclass=MetaModalCLI):
formatter_class
=
RawDescriptionDefaultsHelpFormatter
,
)
if
self
.
version
is
not
None
:
if
hasattr
(
self
,
'
version
'
)
and
self
.
version
is
not
None
:
parser
.
add_argument
(
'
--version
'
,
action
=
'
store_true
'
,
help
=
'
show version number and exit
'
)
...
...
@@ -304,10 +326,18 @@ class ModalCLI(metaclass=MetaModalCLI):
for
cmdinfo
in
cmdinfo_list
:
# group = cmdinfo['group']
# Add a new command to subparser_group
subparser
=
command_subparsers
.
add_parser
(
cmdinfo
[
'
cmdname
'
],
**
cmdinfo
[
'
parserkw
'
])
subparser
=
cmdinfo
[
'
subconfig
'
].
argparse
(
subparser
)
subparser
.
set_defaults
(
main
=
cmdinfo
[
'
main_func
'
])
if
cmdinfo
[
'
is_modal
'
]:
modal_cls
=
cmdinfo
[
'
subconfig
'
]
modal_inst
=
modal_cls
()
modal_parser
=
command_subparsers
.
add_parser
(
cmdinfo
[
'
cmdname
'
],
**
cmdinfo
[
'
parserkw
'
])
modal_parser
=
modal_inst
.
argparse
(
parser
=
modal_parser
)
modal_parser
.
set_defaults
(
main
=
cmdinfo
[
'
main_func
'
])
else
:
subparser
=
command_subparsers
.
add_parser
(
cmdinfo
[
'
cmdname
'
],
**
cmdinfo
[
'
parserkw
'
])
subparser
=
cmdinfo
[
'
subconfig
'
].
argparse
(
subparser
)
subparser
.
set_defaults
(
main
=
cmdinfo
[
'
main_func
'
])
return
parser
build_parser
=
argparse
...
...
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