Skip to content

Commit 1597b0f

Browse files
committed
start work on in house shell completer classes #156
1 parent 3738c1a commit 1597b0f

File tree

7 files changed

+50
-6
lines changed

7 files changed

+50
-6
lines changed

django_typer/management/commands/shellcompletion.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,9 @@
4646
from django.utils.translation import gettext_lazy as _
4747
from shellingham import ShellDetectionFailure, detect_shell
4848
from typer import Argument, Option, echo
49-
from typer.completion import ( # type: ignore
50-
Shells, # pyright: ignore[reportPrivateImportUsage]
51-
completion_init, # pyright: ignore[reportPrivateImportUsage]
52-
)
5349

5450
from django_typer.management import TyperCommand, command, get_command, initialize
51+
from django_typer.management.commands.shells import Shells, completion_init
5552
from django_typer.types import COMMON_PANEL
5653
from django_typer.utils import get_usage_script
5754

@@ -65,6 +62,7 @@
6562
DJANGO_COMMAND = Path(__file__).name.split(".")[0]
6663

6764

65+
6866
class Command(TyperCommand):
6967
"""
7068
This command installs autocompletion for the current shell. This command uses the typer/click
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from enum import Enum
2+
from click.shell_completion import add_completion_class
3+
4+
5+
class Shells(str, Enum):
6+
bash = "bash"
7+
zsh = "zsh"
8+
fish = "fish"
9+
powershell = "powershell"
10+
pwsh = "pwsh"
11+
12+
13+
def completion_init():
14+
from .bash import BashComplete
15+
from .fish import FishComplete
16+
from .powershell import PowerShellComplete
17+
from .zsh import ZshComplete
18+
19+
add_completion_class(BashComplete, Shells.bash)
20+
add_completion_class(ZshComplete, Shells.zsh)
21+
add_completion_class(FishComplete, Shells.fish)
22+
add_completion_class(PowerShellComplete, Shells.powershell)
23+
add_completion_class(PowerShellComplete, Shells.pwsh)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from click.shell_completion import BashComplete as ClickBashComplete
2+
3+
4+
class BashComplete(ClickBashComplete):
5+
pass
6+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from click.shell_completion import FishComplete as ClickFishComplete
2+
3+
4+
class FishComplete(ClickFishComplete):
5+
pass
6+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from click.shell_completion import ShellComplete
2+
3+
4+
class PowerShellComplete(ShellComplete):
5+
pass
6+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from click.shell_completion import ZshComplete as ClickZshComplete
2+
3+
4+
class ZshComplete(ClickZshComplete):
5+
pass

justfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ check-package:
3434
poetry run pip check
3535

3636
clean-docs:
37-
python -c "from shutil import rmtree; rmtree('./doc/build', ignore_errors=True)"
37+
python -c "import shutil; shutil.rmtree('./doc/build', ignore_errors=True)"
3838

3939
clean-env:
40-
python -c "import shutil, sys; shutil.rmtree(sys.argv[1])" $(poetry env info --path)
40+
python -c "import shutil, sys; shutil.rmtree(sys.argv[1], ignore_errors=True)" $(poetry env info --path)
4141

4242
clean-git-ignored:
4343
git clean -fdX

0 commit comments

Comments
 (0)