forked from platformio/platformio-core
Switch to Click meta context for lib CLI
This commit is contained in:
@ -32,6 +32,8 @@ try:
|
||||
except ImportError:
|
||||
from urllib import quote
|
||||
|
||||
CTX_META_STORAGE_DIRS_KEY = __name__ + ".storage_dirs"
|
||||
|
||||
|
||||
@click.group(short_help="Library Manager")
|
||||
@click.option(
|
||||
@ -82,7 +84,8 @@ def cli(ctx, **options):
|
||||
raise exception.NotGlobalLibDir(get_project_dir(),
|
||||
join(util.get_home_dir(), "lib"),
|
||||
ctx.invoked_subcommand)
|
||||
ctx.obj = []
|
||||
|
||||
ctx.meta[CTX_META_STORAGE_DIRS_KEY] = []
|
||||
for storage_dir in storage_dirs:
|
||||
if is_platformio_project(storage_dir):
|
||||
with util.cd(storage_dir):
|
||||
@ -93,9 +96,10 @@ def cli(ctx, **options):
|
||||
for env in config.envs():
|
||||
if (not options['environment']
|
||||
or env in options['environment']):
|
||||
ctx.obj.append(join(libdeps_dir, env))
|
||||
ctx.meta[CTX_META_STORAGE_DIRS_KEY].append(
|
||||
join(libdeps_dir, env))
|
||||
else:
|
||||
ctx.obj.append(storage_dir)
|
||||
ctx.meta[CTX_META_STORAGE_DIRS_KEY].append(storage_dir)
|
||||
|
||||
|
||||
@cli.command("install", short_help="Install library")
|
||||
@ -116,8 +120,9 @@ def cli(ctx, **options):
|
||||
"--force",
|
||||
is_flag=True,
|
||||
help="Reinstall/redownload library if exists")
|
||||
@click.pass_obj
|
||||
def lib_install(storage_dirs, libraries, silent, interactive, force):
|
||||
@click.pass_context
|
||||
def lib_install(ctx, libraries, silent, interactive, force):
|
||||
storage_dirs = ctx.meta[CTX_META_STORAGE_DIRS_KEY]
|
||||
for storage_dir in storage_dirs:
|
||||
print_storage_header(storage_dirs, storage_dir)
|
||||
lm = LibraryManager(storage_dir)
|
||||
@ -128,8 +133,9 @@ def lib_install(storage_dirs, libraries, silent, interactive, force):
|
||||
|
||||
@cli.command("uninstall", short_help="Uninstall libraries")
|
||||
@click.argument("libraries", nargs=-1, metavar="[LIBRARY...]")
|
||||
@click.pass_obj
|
||||
def lib_uninstall(storage_dirs, libraries):
|
||||
@click.pass_context
|
||||
def lib_uninstall(ctx, libraries):
|
||||
storage_dirs = ctx.meta[CTX_META_STORAGE_DIRS_KEY]
|
||||
for storage_dir in storage_dirs:
|
||||
print_storage_header(storage_dirs, storage_dir)
|
||||
lm = LibraryManager(storage_dir)
|
||||
@ -149,8 +155,9 @@ def lib_uninstall(storage_dirs, libraries):
|
||||
is_flag=True,
|
||||
help="Do not update, only check for the new versions")
|
||||
@click.option("--json-output", is_flag=True)
|
||||
@click.pass_obj
|
||||
def lib_update(storage_dirs, libraries, only_check, dry_run, json_output):
|
||||
@click.pass_context
|
||||
def lib_update(ctx, libraries, only_check, dry_run, json_output):
|
||||
storage_dirs = ctx.meta[CTX_META_STORAGE_DIRS_KEY]
|
||||
only_check = dry_run or only_check
|
||||
json_result = {}
|
||||
for storage_dir in storage_dirs:
|
||||
@ -196,8 +203,9 @@ def lib_update(storage_dirs, libraries, only_check, dry_run, json_output):
|
||||
|
||||
@cli.command("list", short_help="List installed libraries")
|
||||
@click.option("--json-output", is_flag=True)
|
||||
@click.pass_obj
|
||||
def lib_list(storage_dirs, json_output):
|
||||
@click.pass_context
|
||||
def lib_list(ctx, json_output):
|
||||
storage_dirs = ctx.meta[CTX_META_STORAGE_DIRS_KEY]
|
||||
json_result = {}
|
||||
for storage_dir in storage_dirs:
|
||||
if not json_output:
|
||||
|
@ -20,6 +20,7 @@ import click
|
||||
|
||||
from platformio import exception, telemetry, util
|
||||
from platformio.commands.device import device_monitor as cmd_device_monitor
|
||||
from platformio.commands.lib import CTX_META_STORAGE_DIRS_KEY
|
||||
from platformio.commands.lib import lib_install as cmd_lib_install
|
||||
from platformio.commands.platform import \
|
||||
platform_install as cmd_platform_install
|
||||
@ -272,7 +273,9 @@ def _handle_legacy_libdeps(project_dir, config):
|
||||
def _autoinstall_libdeps(ctx, envname, libraries, verbose=False):
|
||||
if not libraries:
|
||||
return
|
||||
ctx.obj = [join(get_projectlibdeps_dir(), envname)]
|
||||
ctx.meta[CTX_META_STORAGE_DIRS_KEY] = [
|
||||
join(get_projectlibdeps_dir(), envname)
|
||||
]
|
||||
for lib in libraries:
|
||||
try:
|
||||
ctx.invoke(cmd_lib_install, libraries=[lib], silent=not verbose)
|
||||
|
@ -15,6 +15,7 @@
|
||||
import click
|
||||
|
||||
from platformio import app
|
||||
from platformio.commands.lib import CTX_META_STORAGE_DIRS_KEY
|
||||
from platformio.commands.lib import lib_update as cmd_lib_update
|
||||
from platformio.commands.platform import platform_update as cmd_platform_update
|
||||
from platformio.managers.core import update_core_packages
|
||||
@ -54,5 +55,5 @@ def cli(ctx, core_packages, only_check, dry_run):
|
||||
click.echo()
|
||||
click.echo("Library Manager")
|
||||
click.echo("===============")
|
||||
ctx.obj = [LibraryManager().package_dir]
|
||||
ctx.meta[CTX_META_STORAGE_DIRS_KEY] = [LibraryManager().package_dir]
|
||||
ctx.invoke(cmd_lib_update, only_check=only_check)
|
||||
|
@ -23,6 +23,7 @@ import semantic_version
|
||||
|
||||
from platformio import __version__, app, exception, telemetry, util
|
||||
from platformio.commands import PlatformioCLI
|
||||
from platformio.commands.lib import CTX_META_STORAGE_DIRS_KEY
|
||||
from platformio.commands.lib import lib_update as cmd_lib_update
|
||||
from platformio.commands.platform import \
|
||||
platform_install as cmd_platform_install
|
||||
@ -332,7 +333,7 @@ def check_internal_updates(ctx, what):
|
||||
if what == "platforms":
|
||||
ctx.invoke(cmd_platform_update, platforms=outdated_items)
|
||||
elif what == "libraries":
|
||||
ctx.obj = [pm.package_dir]
|
||||
ctx.meta[CTX_META_STORAGE_DIRS_KEY] = [pm.package_dir]
|
||||
ctx.invoke(cmd_lib_update, libraries=outdated_items)
|
||||
click.echo()
|
||||
|
||||
|
Reference in New Issue
Block a user