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