This commit is contained in:
Daylin Morgan 2023-05-27 17:00:54 -05:00
parent 298e8b274c
commit baad1783a2
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F

View file

@ -52,7 +52,7 @@ from typing import (
from urllib.error import HTTPError from urllib.error import HTTPError
from urllib.request import urlopen from urllib.request import urlopen
__version__ = "23.5a1-dev" __version__ = "23.5a1-12-g298e8b2"
@dataclass @dataclass
@ -593,6 +593,16 @@ UPDATE_TEMPLATE = f"""
""" """
SHIM_TEMPLATE = """\
#!/usr/bin/env python3
import subprocess
import sys
if __name__ == "__main__":
vivenv = {use}
sys.exit(subprocess.run([vivenv.path / "bin" / "{bin}", *sys.argv[1:]]).returncode)
"""
def noqa(txt: str) -> str: def noqa(txt: str) -> str:
max_length = max(map(len, txt.splitlines())) max_length = max(map(len, txt.splitlines()))
@ -1126,7 +1136,24 @@ class Viv:
def shim(self, args): def shim(self, args):
"""generate viv-powered cli apps""" """generate viv-powered cli apps"""
echo("not implemented.") if args.output.is_file():
error(f"{args.output} already exists...exiting", code=1)
# TODO: robustness....
spec = ", ".join(f'"{req}"' for req in args.reqs)
if args.bin:
bin = args.bin
elif len(args.reqs) == 1:
bin = args.reqs[0]
else:
error("please specify an explicit -b/--bin")
with args.output.open("w") as f:
f.write(SHIM_TEMPLATE.format(use=f'__import__("viv").use({spec})', bin=bin))
make_executable(args.output)
def _get_subcmd_parser( def _get_subcmd_parser(
self, self,
@ -1299,6 +1326,8 @@ class Viv:
"-o", "-o",
"--output", "--output",
help="path/to/output file", help="path/to/output file",
required=True,
type=Path,
metavar="<path>", metavar="<path>",
) )
p_manage_shim.add_argument( p_manage_shim.add_argument(