Skip to content

Commit

Permalink
refactor completer
Browse files Browse the repository at this point in the history
update node completer cache in `comfy update`
  • Loading branch information
ltdrdata committed May 13, 2024
1 parent a468abd commit bdb33d1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
10 changes: 9 additions & 1 deletion comfy_cli/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,13 @@ def install(

@app.command(help="Update ComfyUI Environment [all|comfy]")
@tracking.track_command()
def update(target: str = typer.Argument("comfy", help="[all|comfy]")):
def update(
target: str = typer.Argument(
"comfy",
help="[all|comfy]",
autocompletion=utils.create_choice_completer(["all", "comfy"]),
)
):
if target not in ["all", "comfy"]:
typer.echo(
f"Invalid target: {target}. Allowed targets are 'all', 'comfy'.",
Expand All @@ -277,6 +283,8 @@ def update(target: str = typer.Argument("comfy", help="[all|comfy]")):
check=True,
)

custom_nodes.command.update_node_id_cache()


# @app.command(help="Run workflow file")
# @tracking.track_command()
Expand Down
19 changes: 9 additions & 10 deletions comfy_cli/command/custom_nodes/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from rich import print
from typing_extensions import List, Annotated

from comfy_cli import ui, logging, tracking
from comfy_cli import ui, logging, tracking, utils
from comfy_cli.config_manager import ConfigManager
from comfy_cli.file_utils import (
download_file,
Expand Down Expand Up @@ -168,8 +168,9 @@ def clear(path: str):
execute_cm_cli(["clear", path])


def show_completer(incomplete: str) -> list[str]:
valid_choices = [
# completers
show_completer = utils.create_choice_completer(
[
"installed",
"enabled",
"not-installed",
Expand All @@ -178,17 +179,15 @@ def show_completer(incomplete: str) -> list[str]:
"snapshot",
"snapshot-list",
]
return [choice for choice in valid_choices if choice.startswith(incomplete)]
)


def mode_completer(incomplete: str) -> list[str]:
modes = ["remote", "local", "cache"]
return [mode for mode in modes if mode.startswith(incomplete)]
mode_completer = utils.create_choice_completer(["remote", "local", "cache"])


def channel_completer(incomplete: str) -> list[str]:
channels = ["default", "recent", "dev", "forked", "tutorial", "legacy"]
return [channel for channel in channels if channel.startswith(incomplete)]
channel_completer = utils.create_choice_completer(
["default", "recent", "dev", "forked", "tutorial", "legacy"]
)


def node_completer(incomplete: str) -> list[str]:
Expand Down
7 changes: 7 additions & 0 deletions comfy_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,10 @@ def is_running(pid):
return True
except psutil.NoSuchProcess:
return False


def create_choice_completer(opts):
def f(incomplete: str) -> list[str]:
return [opt for opt in opts if opt.startswith(incomplete)]

return f

0 comments on commit bdb33d1

Please sign in to comment.