mirror of
https://github.com/ihabunek/toot.git
synced 2025-02-02 15:07:51 -05:00
Add shell completion for instances
This commit is contained in:
parent
22c9f387a1
commit
2e2945822a
@ -110,6 +110,20 @@ class AccountParamType(StringParamType):
|
||||
]
|
||||
|
||||
|
||||
class InstanceParamType(StringParamType):
|
||||
"""Custom type to add shell completion for instance domains"""
|
||||
name = "instance"
|
||||
|
||||
def shell_complete(self, ctx, param, incomplete: str):
|
||||
apps = config.load_config()["apps"]
|
||||
|
||||
return [
|
||||
CompletionItem(i)
|
||||
for i in apps.keys()
|
||||
if i.lower().startswith(incomplete.lower())
|
||||
]
|
||||
|
||||
|
||||
def pass_context(f: "t.Callable[te.Concatenate[Context, P], R]") -> "t.Callable[P, R]":
|
||||
"""Pass the toot Context as first argument."""
|
||||
@wraps(f)
|
||||
|
@ -9,7 +9,7 @@ from toot.cli.validators import validate_instance
|
||||
from toot.entities import Instance, Status, from_dict, Account
|
||||
from toot.exceptions import ApiError, ConsoleError
|
||||
from toot.output import print_account, print_instance, print_search_results, print_status, print_timeline
|
||||
from toot.cli import cli, get_context, json_option, pass_context, Context
|
||||
from toot.cli import InstanceParamType, cli, get_context, json_option, pass_context, Context
|
||||
|
||||
|
||||
@cli.command()
|
||||
@ -43,7 +43,7 @@ def whois(ctx: Context, account: str, json: bool):
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.argument("instance", callback=validate_instance, required=False)
|
||||
@click.argument("instance", type=InstanceParamType(), callback=validate_instance, required=False)
|
||||
@json_option
|
||||
def instance(instance: Optional[str], json: bool):
|
||||
"""Display instance details
|
||||
|
@ -2,7 +2,7 @@ import sys
|
||||
import click
|
||||
|
||||
from toot import api
|
||||
from toot.cli import cli, get_context, pass_context, Context
|
||||
from toot.cli import InstanceParamType, cli, get_context, pass_context, Context
|
||||
from typing import Optional
|
||||
from toot.cli.validators import validate_instance
|
||||
|
||||
@ -13,6 +13,7 @@ from toot.output import print_notifications, print_timeline
|
||||
@cli.command()
|
||||
@click.option(
|
||||
"--instance", "-i",
|
||||
type=InstanceParamType(),
|
||||
callback=validate_instance,
|
||||
help="""Domain or base URL of the instance from which to read,
|
||||
e.g. 'mastodon.social' or 'https://mastodon.social'""",
|
||||
|
Loading…
x
Reference in New Issue
Block a user