Skip to content

Commit 5b4c9dc

Browse files
authored
Merge pull request piccolo-orm#100 from piccolo-orm/command_aliases
Added aliases for CLI commands
2 parents 2feb562 + e89a9a1 commit 5b4c9dc

File tree

12 files changed

+71
-23
lines changed

12 files changed

+71
-23
lines changed

piccolo/apps/app/piccolo_app.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
from piccolo.conf.apps import AppConfig
1+
from piccolo.conf.apps import AppConfig, Command
22
from .commands.new import new
33
from .commands.show_all import show_all
44

55

66
APP_CONFIG = AppConfig(
7-
app_name="app", migrations_folder_path="", commands=[new, show_all]
7+
app_name="app",
8+
migrations_folder_path="",
9+
commands=[
10+
Command(callable=new, aliases=["create"]),
11+
Command(callable=show_all, aliases=["show", "all", "list"]),
12+
],
813
)

piccolo/apps/asgi/piccolo_app.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
from piccolo.conf.apps import AppConfig
1+
from piccolo.conf.apps import AppConfig, Command
22
from .commands.new import new
33

44

55
APP_CONFIG = AppConfig(
6-
app_name="asgi", migrations_folder_path="", commands=[new]
6+
app_name="asgi",
7+
migrations_folder_path="",
8+
commands=[Command(callable=new, aliases=["create"])],
79
)

piccolo/apps/meta/piccolo_app.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
from piccolo.conf.apps import AppConfig
1+
from piccolo.conf.apps import AppConfig, Command
22
from .commands.version import version
33

44

55
APP_CONFIG = AppConfig(
6-
app_name="meta", migrations_folder_path="", commands=[version]
6+
app_name="meta",
7+
migrations_folder_path="",
8+
commands=[Command(callable=version, aliases=["v"])],
79
)

piccolo/apps/migrations/piccolo_app.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from piccolo.conf.apps import AppConfig
1+
from piccolo.conf.apps import AppConfig, Command
22
from .commands.backwards import backwards
33
from .commands.check import check
44
from .commands.clean import clean
@@ -9,5 +9,11 @@
99
APP_CONFIG = AppConfig(
1010
app_name="migrations",
1111
migrations_folder_path="",
12-
commands=[backwards, check, clean, forwards, new],
12+
commands=[
13+
Command(callable=backwards, aliases=["b", "back", "backward"]),
14+
Command(callable=check),
15+
Command(callable=clean),
16+
Command(callable=forwards, aliases=["f", "forward"]),
17+
Command(callable=new, aliases=["n", "create"]),
18+
],
1319
)
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
from piccolo.conf.apps import AppConfig
1+
from piccolo.conf.apps import AppConfig, Command
22
from .commands.run import run
33

44

55
APP_CONFIG = AppConfig(
6-
app_name="playground", migrations_folder_path="", commands=[run]
6+
app_name="playground",
7+
migrations_folder_path="",
8+
commands=[Command(callable=run, aliases=["start"])],
79
)
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
from piccolo.conf.apps import AppConfig
1+
from piccolo.conf.apps import AppConfig, Command
22
from .commands.new import new
33

44

55
APP_CONFIG = AppConfig(
6-
app_name="project", migrations_folder_path="", commands=[new]
6+
app_name="project",
7+
migrations_folder_path="",
8+
commands=[Command(callable=new, aliases=["create"])],
79
)

piccolo/apps/shell/piccolo_app.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
from piccolo.conf.apps import AppConfig
1+
from piccolo.conf.apps import AppConfig, Command
22
from .commands.run import run
33

44

55
APP_CONFIG = AppConfig(
6-
app_name="shell", migrations_folder_path="", commands=[run]
6+
app_name="shell",
7+
migrations_folder_path="",
8+
commands=[Command(callable=run, aliases=["start"])],
79
)
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
from piccolo.conf.apps import AppConfig
1+
from piccolo.conf.apps import AppConfig, Command
22
from .commands.run import run
33

44

55
APP_CONFIG = AppConfig(
6-
app_name="sql_shell", migrations_folder_path="", commands=[run]
6+
app_name="sql_shell",
7+
migrations_folder_path="",
8+
commands=[Command(callable=run, aliases=["start"])],
79
)

piccolo/apps/user/piccolo_app.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22

3-
from piccolo.conf.apps import AppConfig
3+
from piccolo.conf.apps import AppConfig, Command
44
from .commands.change_password import change_password
55
from .commands.change_permissions import change_permissions
66
from .commands.create import create
@@ -17,5 +17,9 @@
1717
),
1818
table_classes=[BaseUser],
1919
migration_dependencies=[],
20-
commands=[create, change_password, change_permissions],
20+
commands=[
21+
Command(callable=create, aliases=["new"]),
22+
Command(callable=change_password, aliases=["password", "pass"]),
23+
Command(callable=change_permissions, aliases=["perm", "perms"]),
24+
],
2125
)

piccolo/conf/apps.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ def table_finder(
8484
return table_subclasses
8585

8686

87+
@dataclass
88+
class Command:
89+
callable: t.Callable
90+
aliases: t.List[str] = field(default_factory=list)
91+
92+
8793
@dataclass
8894
class AppConfig:
8995
"""
@@ -94,7 +100,14 @@ class AppConfig:
94100
migrations_folder_path: str
95101
table_classes: t.List[t.Type[Table]] = field(default_factory=list)
96102
migration_dependencies: t.List[str] = field(default_factory=list)
97-
commands: t.List[t.Callable] = field(default_factory=list)
103+
commands: t.List[t.Union[t.Callable, Command]] = field(
104+
default_factory=list
105+
)
106+
107+
def __post_init__(self):
108+
self.commands = [
109+
i if isinstance(i, Command) else Command(i) for i in self.commands
110+
]
98111

99112
def register_table(self, table_class: t.Type[Table]):
100113
self.table_classes.append(table_class)

0 commit comments

Comments
 (0)