Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
beat
beat.cmdline
Commits
ce4c270a
Commit
ce4c270a
authored
May 23, 2018
by
Theophile GENTILHOMME
Browse files
[click_helper] Implement AliasedGroup.
Implements get_command used for commands aliasing. Use prefix aliasing.
parent
8cc48236
Changes
1
Hide whitespace changes
Inline
Side-by-side
beat/cmdline/scripts/click_helper.py
View file @
ce4c270a
...
...
@@ -10,6 +10,7 @@ try:
except
NameError
:
basestring
=
str
def
verbosity_option
(
**
kwargs
):
"""Adds a -v/--verbose option to a click command.
...
...
@@ -37,3 +38,18 @@ def verbosity_option(**kwargs):
"--verbose option as often as desired (e.g. '-vvv' for debug)."
,
callback
=
callback
,
**
kwargs
)(
f
)
return
custom_verbosity_option
class
AliasedGroup
(
click
.
Group
):
def
get_command
(
self
,
ctx
,
cmd_name
):
rv
=
click
.
Group
.
get_command
(
self
,
ctx
,
cmd_name
)
if
rv
is
not
None
:
return
rv
matches
=
[
x
for
x
in
self
.
list_commands
(
ctx
)
if
x
.
startswith
(
cmd_name
)]
if
not
matches
:
return
None
elif
len
(
matches
)
==
1
:
return
click
.
Group
.
get_command
(
self
,
ctx
,
matches
[
0
])
ctx
.
fail
(
'Too many matches: %s'
%
', '
.
join
(
sorted
(
matches
)))
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment