fix: accept args with -s to make shebangs work better

This commit is contained in:
Daylin Morgan 2023-09-27 12:42:32 -05:00
parent 2e916cab5f
commit da77259862
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F
2 changed files with 10 additions and 8 deletions

View file

@ -4,14 +4,10 @@
# Script Dependencies:
# requests
# rich # Needed for the output
#
# # Not needed - just to show that fragments in URLs do not
# # get treated as comments
# pip @ https://github.com/pypa/pip/archive/1.3.1.zip#sha1=2e15a2d4e7e9f394a9c7a6c905c6a239402a6442
import requests
from rich.pretty import pprint
from rich import print
resp = requests.get("https://peps.python.org/api/peps.json")
data = resp.json()
pprint([(k, v["title"]) for k, v in data.items()][:10])
print([(k, v["title"]) for k, v in data.items()][:10])

View file

@ -52,7 +52,7 @@ from typing import (
Union,
)
__version__ = "2023.1002"
__version__ = "2023.1002-dev"
class Spinner:
@ -1792,7 +1792,9 @@ class Viv:
examples:
viv r pycowsay -- "viv isn't venv\!"
viv r rich -b python -- -m rich
viv r -s <remote python script>
viv r -s <python script>
note: any args after `-s <python script>` will be passed on
"""
spec = combined_spec(reqs, requirements)
@ -2127,6 +2129,10 @@ class Cli:
i = sys.argv.index("--")
args = self.parser.parse_args(sys.argv[1:i])
args.rest = sys.argv[i + 1 :]
elif flag := list({"-s", "--script"} & set(sys.argv)):
i = sys.argv.index(flag[0])
args = self.parser.parse_args(sys.argv[1 : i + 2])
args.rest = sys.argv[i + 2 :]
else:
args = self.parser.parse_args()
if args.func.__name__ in ("cmd_run", "cmd_exe"):