File tree Expand file tree Collapse file tree 1 file changed +26
-2
lines changed
src/pkgmt/assets/template/src/package_name Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Original file line number Diff line number Diff line change 5
5
import click
6
6
7
7
8
- @click .group ()
8
+ class AliasedGroup (click .Group ):
9
+ """
10
+ Allow running commands by only typing the first few characters.
11
+ https://click.palletsprojects.com/en/8.1.x/advanced/#command-aliases
12
+
13
+ To disable, remove the `cls=AliasedGroup` argument from the `@click.group()` decorator.
14
+ """
15
+
16
+ def get_command (self , ctx , cmd_name ):
17
+ rv = click .Group .get_command (self , ctx , cmd_name )
18
+ if rv is not None :
19
+ return rv
20
+ matches = [x for x in self .list_commands (ctx ) if x .startswith (cmd_name )]
21
+ if not matches :
22
+ return None
23
+ elif len (matches ) == 1 :
24
+ return click .Group .get_command (self , ctx , matches [0 ])
25
+ ctx .fail (f"Too many matches: { ', ' .join (sorted (matches ))} " )
26
+
27
+ def resolve_command (self , ctx , args ):
28
+ # always return the full command name
29
+ _ , cmd , args = super ().resolve_command (ctx , args )
30
+ return cmd .name , cmd , args
31
+
32
+
33
+ @click .group (cls = AliasedGroup )
9
34
def cli ():
10
- """Command-line interface"""
11
35
pass
12
36
13
37
You can’t perform that action at this time.
0 commit comments