Skip to content

Commit

Permalink
Add shell completion for account names
Browse files Browse the repository at this point in the history
  • Loading branch information
ihabunek committed Dec 7, 2023
1 parent c7b5669 commit 0848a6f
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions toot/cli/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import platform
import sys
import webbrowser
from click.shell_completion import CompletionItem

from click.types import StringParamType

from toot import api, config, __version__
from toot.auth import get_or_create_app, login_auth_code, login_username_password
Expand All @@ -19,6 +22,18 @@
)


class AccountParamType(StringParamType):
"""Custom type to add shell completion for account names"""

def shell_complete(self, ctx, param, incomplete: str):
accounts = config.load_config()["users"].keys()
return [
CompletionItem(a)
for a in accounts
if a.lower().startswith(incomplete.lower())
]


@cli.command()
def auth():
"""Show logged in accounts and instances"""
Expand Down Expand Up @@ -101,7 +116,7 @@ def login(base_url: str):


@cli.command()
@click.argument("account", required=False)
@click.argument("account", type=AccountParamType(), required=False)
def logout(account: str):
"""Log out of ACCOUNT, delete stored access keys"""
accounts = _get_accounts_list()
Expand All @@ -119,7 +134,7 @@ def logout(account: str):


@cli.command()
@click.argument("account", required=False)
@click.argument("account", type=AccountParamType(), required=False)
def activate(account: str):
"""Switch to logged in ACCOUNT."""
accounts = _get_accounts_list()
Expand Down

0 comments on commit 0848a6f

Please sign in to comment.