Compare commits

...

4 Commits

Author SHA1 Message Date
d8c3cd2e36 Add --quiet 2022-04-08 14:17:01 -07:00
3e3c44075a Reorder options 2022-04-08 14:13:58 -07:00
50292eb2cb Make -s and -p mutually exclusive 2022-04-08 14:13:06 -07:00
3ab5be69a1 Improve command-line output 2022-04-08 14:11:23 -07:00

View File

@ -2,6 +2,7 @@
import requests
import subprocess
import sys
import os
import argparse
import shlex
@ -35,38 +36,51 @@ parser = argparse.ArgumentParser(
)
parser.add_argument("url", help="URL of the script")
parser.add_argument(
"-s",
"--skip-pager",
action="store_true",
help="Skip pager and confirmation; run script immediately",
"-i",
"--interpreter",
help="Choose interpreter to use (default: `bash`)",
default="bash",
)
parser.add_argument(
group = parser.add_mutually_exclusive_group()
group.add_argument(
"-p",
"--pager",
help="Choose pager to use (default: `less`)",
default="less",
)
parser.add_argument(
"-i",
"--interpreter",
help="Choose interpreter to use (default: `bash`)",
default="bash",
group.add_argument(
"-s",
"--skip-pager",
action="store_true",
help="Skip pager and confirmation; run script immediately",
)
group.add_argument(
"-q",
"--quiet",
action="store_true",
help="Skip pager and confirmation; run script immediately; do not print anything",
)
args = parser.parse_args()
url = args.url
pager = shlex.split(args.pager)
interpreter = shlex.split(args.interpreter)
if not args.quiet:
print(f"Downloading `{url}`...")
content = requests.get(url).content
if not args.quiet:
print("Download successful.")
print("=" * os.get_terminal_size().columns)
if args.skip_pager:
if args.skip_pager or args.quiet:
launch(interpreter, content)
else:
launch(pager, content)
response = yn("Do you want to run this script?")
if response == "y":
print("=" * 20)
print("=" * os.get_terminal_size().columns)
launch(interpreter, content)
else:
print("=" * os.get_terminal_size().columns)
print("Script not run.")