|
| 1 | +from typing import Optional |
| 2 | + |
| 3 | +import click |
| 4 | + |
| 5 | +import commodore.cli.options as options |
| 6 | + |
| 7 | +from commodore import tools |
| 8 | +from commodore.config import Config |
| 9 | + |
| 10 | + |
| 11 | +@click.group( |
| 12 | + name="tool", |
| 13 | + short_help="Manage required external tools", |
| 14 | +) |
| 15 | +@options.verbosity |
| 16 | +@options.pass_config |
| 17 | +@options.github_token |
| 18 | +def tool_group(config: Config, verbose: int, github_token: str): |
| 19 | + config.update_verbosity(verbose) |
| 20 | + config.managed_tools = tools.load_state() |
| 21 | + config.github_token = github_token |
| 22 | + |
| 23 | + |
| 24 | +@tool_group.command(name="list", short_help="List external tools") |
| 25 | +@options.verbosity |
| 26 | +@options.pass_config |
| 27 | +@options.github_token |
| 28 | +@click.option( |
| 29 | + "--version-check/--skip-version-check", |
| 30 | + " / -V", |
| 31 | + default=True, |
| 32 | + help="Query GitHub API to get latest version", |
| 33 | +) |
| 34 | +def tool_list(config: Config, verbose: int, github_token: str, version_check: bool): |
| 35 | + config.update_verbosity(verbose) |
| 36 | + config.github_token = github_token |
| 37 | + tools.list_tools(config, version_check) |
| 38 | + |
| 39 | + |
| 40 | +@tool_group.command(name="install", short_help="Install external tools") |
| 41 | +@options.verbosity |
| 42 | +@options.pass_config |
| 43 | +@options.github_token |
| 44 | +@click.option( |
| 45 | + "--version", |
| 46 | + default=None, |
| 47 | + metavar="VERSION", |
| 48 | + help="A custom version to install for the requested tool (by default the latest version is installed)", |
| 49 | +) |
| 50 | +@click.argument("tool") |
| 51 | +def tool_install( |
| 52 | + config: Config, verbose: int, tool: str, version: Optional[str], github_token: str |
| 53 | +): |
| 54 | + config.update_verbosity(verbose) |
| 55 | + config.github_token = github_token |
| 56 | + tools.install_tool(config, tool, version) |
| 57 | + |
| 58 | + |
| 59 | +@tool_group.command(name="upgrade", short_help="Upgrade external tools") |
| 60 | +@options.verbosity |
| 61 | +@options.github_token |
| 62 | +@options.pass_config |
| 63 | +@click.option( |
| 64 | + "--version", |
| 65 | + default=None, |
| 66 | + metavar="VERSION", |
| 67 | + help="A custom version to install for the requested tool (by default the latest version is installed)", |
| 68 | +) |
| 69 | +@click.argument("tool") |
| 70 | +def tool_upgrade( |
| 71 | + config: Config, verbose: int, tool: str, version: Optional[str], github_token: str |
| 72 | +): |
| 73 | + config.update_verbosity(verbose) |
| 74 | + config.github_token = github_token |
| 75 | + tools.upgrade_tool(config, tool, version) |
0 commit comments