feat: add -y flag to avoid prompts

This commit is contained in:
Daylin Morgan 2023-06-02 17:10:28 -05:00
parent e70afb3eac
commit 2bc247673e
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F
3 changed files with 22 additions and 10 deletions

View file

@ -33,7 +33,7 @@ docs/index.md: README.md
examples/black: .FORCE examples/black: .FORCE
rm -f $@ rm -f $@
viv shim black -s -f -o $@ viv shim black -y -s -f -o $@
clean: ## remove build artifacts clean: ## remove build artifacts
rm -rf {build,dist} rm -rf {build,dist}

View file

@ -1,5 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
# AUTOGENERATED by viv (v23.5a4-37-gf8ebd9d-dev) # AUTOGENERATED by viv (v23.5a5-1-g853e6e6-dev)
# see `python3 <(curl -fsSL viv.dayl.in/viv.py) --help` # see `python3 <(curl -fsSL viv.dayl.in/viv.py) --help`

View file

@ -50,7 +50,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.5a5-1-g853e6e6-dev" __version__ = "23.5a5-2-ge70afb3-dev"
class Spinner: class Spinner:
@ -386,11 +386,15 @@ def warn(msg: str) -> None:
echo(f"{a.yellow}warn:{a.end} {msg}", style="yellow") echo(f"{a.yellow}warn:{a.end} {msg}", style="yellow")
def confirm(question: str, context: str = "") -> bool: def confirm(question: str, context: str = "", yes: bool = False) -> bool:
sys.stderr.write(context) sys.stderr.write(context)
sys.stderr.write( sys.stderr.write(
a.viv_preamble(sep="?? ") + question + a.style(" (Y)es/(n)o ", "yellow") a.viv_preamble(sep="?? ") + question + a.style(" (Y)es/(n)o ", "yellow")
) )
if yes:
sys.stderr.write(f"{a.green}[FORCED YES]{a.end}\n")
return True
while True: while True:
ans = input().strip().lower() ans = input().strip().lower()
if ans in ("y", "yes"): if ans in ("y", "yes"):
@ -1056,7 +1060,7 @@ class Viv:
else: else:
vivenv.tree() vivenv.tree()
def _install_local_src(self, sha256: str, src: Path, cli: Path) -> None: def _install_local_src(self, sha256: str, src: Path, cli: Path, yes: bool) -> None:
echo("updating local source copy of viv") echo("updating local source copy of viv")
shutil.copy(c.srccache / f"{sha256}.py", src) shutil.copy(c.srccache / f"{sha256}.py", src)
make_executable(src) make_executable(src)
@ -1064,7 +1068,7 @@ class Viv:
if cli.is_file(): if cli.is_file():
echo(f"Existing file at {a.style(str(cli),'bold')}") echo(f"Existing file at {a.style(str(cli),'bold')}")
if confirm("Would you like to overwrite it?"): if confirm("Would you like to overwrite it?", yes=yes):
cli.unlink() cli.unlink()
cli.symlink_to(src) cli.symlink_to(src)
else: else:
@ -1109,6 +1113,7 @@ class Viv:
if confirm( if confirm(
"Would you like to perform the above installation steps?", "Would you like to perform the above installation steps?",
t.update(self.local_source, args.cli, self.local_version, next_version), t.update(self.local_source, args.cli, self.local_version, next_version),
yes=args.yes,
): ):
self._install_local_src( self._install_local_src(
sha256, sha256,
@ -1116,6 +1121,7 @@ class Viv:
args.src if not self.local_source else self.local_source, args.src if not self.local_source else self.local_source,
), ),
args.cli, args.cli,
args.yes,
) )
elif args.subcmd == "install": elif args.subcmd == "install":
@ -1129,6 +1135,7 @@ class Viv:
if confirm( if confirm(
"Would you like to perform the above installation steps?", "Would you like to perform the above installation steps?",
t.install(args.src, args.cli), t.install(args.src, args.cli),
yes=args.yes,
): ):
self._install_local_src(sha256, args.src, args.cli) self._install_local_src(sha256, args.src, args.cli)
@ -1153,6 +1160,7 @@ class Viv:
if confirm( if confirm(
"Remove the above files/directories?", "Remove the above files/directories?",
"\n".join(f" - {a.red}{p}{a.end}" for p in to_remove) + "\n", "\n".join(f" - {a.red}{p}{a.end}" for p in to_remove) + "\n",
yes=args.yes,
): ):
for p in to_remove: for p in to_remove:
if p.is_dir(): if p.is_dir():
@ -1191,7 +1199,8 @@ class Viv:
spec = combined_spec(args.reqs, args.requirements) spec = combined_spec(args.reqs, args.requirements)
if confirm( if confirm(
f"Write shim for {a.style(bin,'bold')} to {a.style(output,'green')}?" f"Write shim for {a.style(bin,'bold')} to {a.style(output,'green')}?",
yes=args.yes,
): ):
with output.open("w") as f: with output.open("w") as f:
f.write( f.write(
@ -1368,7 +1377,10 @@ class Cli:
metavar="<cli>", metavar="<cli>",
), ),
], ],
"manage|show": [ ("shim", "manage|purge", "manage|update", "manage|install"): [
Arg("-y", "--yes", help="respond yes to all prompts", action="store_true")
],
("manage|show",): [
Arg( Arg(
"-p", "-p",
"--pythonpath", "--pythonpath",
@ -1376,7 +1388,7 @@ class Cli:
action="store_true", action="store_true",
) )
], ],
("exe"): [ ("exe",): [
Arg( Arg(
"cmd", "cmd",
help="command to to execute", help="command to to execute",