You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromtypingimportTuple, AnyStrimportasynciofromclickimportContextfromrich.progressimportProgressimportclickfromwoke.a_configimportWokeConfigfromwoke.b_svmimportSolcVersionManagerfromwoke.c_regex_parsing.solidity_versionimportSolidityVersion, SolidityVersionExprfrom .consoleimportconsole@click.group(name="svm")@click.pass_contextdefrun_svm(ctx: Context):
"""Run Woke solc version manager."""config=WokeConfig(woke_root_path=ctx.obj["woke_root_path"])
config.load_configs()
ctx.obj["config"] =config@run_svm.command(name="install")@click.argument("version_range", nargs=-1)@click.option("--force", is_flag=True, help="Reinstall the target version if already installed.")@click.pass_contextdefsvm_install(ctx: Context, version_range: Tuple[str], force: bool) ->None:
"""Install the latest solc version matching the given version range."""config: WokeConfig=ctx.obj["config"]
svm=SolcVersionManager(config)
version_expr=SolidityVersionExpr(" ".join(version_range))
asyncio.run(run_solc_install(svm, version_expr, force))
asyncdefrun_solc_install(
svm: SolcVersionManager, version_expr: SolidityVersionExpr, force: bool
) ->None:
version=next(
versionforversioninreversed(svm.list_all()) ifversioninversion_expr
)
withProgress() asprogress:
task=progress.add_task(f"[green]Downloading solc {version}", total=1)
awaitsvm.install(
version,
force_reinstall=force,
progress=(lambdax: progress.update(task, completed=x)),
)
console.print(f"Installed solc version {version}.")
@run_svm.command(name="switch")@click.argument("version", nargs=1)@click.pass_contextdefsvm_switch(ctx: Context, version: str) ->None:
"""Switch to the target version of solc. Raise an exception if the version is not installed."""config: WokeConfig=ctx.obj["config"]
svm=SolcVersionManager(config)
parsed_version=SolidityVersion.fromstring(version)
ifnotsvm.get_path(parsed_version).is_file():
raiseValueError(f"solc version {parsed_version} is not installed.")
(config.woke_root_path/".woke_solc_version").write_text(str(parsed_version))
console.print(f"Using woke-solc version {version}.")
@run_svm.command(name="use")@click.argument("version_range", nargs=-1)@click.option("--force", is_flag=True, help="Reinstall the target version if already installed.")@click.pass_contextdefsvm_use(ctx: Context, version_range: Tuple[str], force: bool) ->None:
"""Install the target solc version and use it as the global version."""config: WokeConfig=ctx.obj["config"]
svm=SolcVersionManager(config)
version_expr=SolidityVersionExpr(" ".join(version_range))
version=next(
versionforversioninreversed(svm.list_all()) ifversioninversion_expr
)
ifnotsvm.get_path(version).is_file():
asyncio.run(run_solc_install(svm, SolidityVersionExpr(str(version)), force))
(config.woke_root_path/".woke_solc_version").write_text(str(version))
console.print(f"Using woke-solc version {version}.")
@run_svm.command(name="list") # TODO alias `ls`@click.option("--all", is_flag=True, help="List all versions including non-installed ones.")@click.pass_contextdefsvm_list(ctx: Context, all: bool) ->None:
"""List installed solc versions."""config: WokeConfig=ctx.obj["config"]
svm=SolcVersionManager(config)
ifall:
installed=set(svm.list_installed())
output="\n".join(
f"- {version}{'([green]installed[/green])'ifversionininstalledelse''}"forversioninsvm.list_all()
)
else:
output="\n".join(f"- {version}"forversioninsvm.list_installed())
console.print(output)
@run_svm.command(name="remove") # TODO alias `rm`@click.argument("version", nargs=1)@click.option("--ignore-missing",is_flag=True,help="do not raise an exception if version to be removed is not installed",)@click.pass_contextdefsvm_remove(ctx: Context, version: str, ignore_missing: bool) ->None:
"""Remove the target solc version."""config: WokeConfig=ctx.obj["config"]
svm=SolcVersionManager(config)
parsed_version=SolidityVersion.fromstring(version)
ifignore_missing:
try:
svm.remove(parsed_version)
console.print(f"Removed solc version {parsed_version}.")
exceptValueError:
console.print(f"solc {parsed_version} is not installed.")
else:
svm.remove(parsed_version)
console.print(f"Removed solc version {parsed_version}.")
10efd432c215dca868176400a285a96f69f994e9
The text was updated successfully, but these errors were encountered:
alias
ls
https://github.com/Ackee-Blockchain/woke/blob/0d27de25720142beb9619a89619b7a94c3556af1/woke/woke/x_cli/svm.py#L92
10efd432c215dca868176400a285a96f69f994e9
The text was updated successfully, but these errors were encountered: