feat: keep positional args in context

This commit is contained in:
Daylin Morgan 2024-10-22 13:05:02 -05:00
parent 5115f72db6
commit 3bf6c4e722
Signed by: daylin
GPG key ID: 950D13E9719334AD

View file

@ -101,6 +101,7 @@ class Context:
self._flag_defs: List[Tuple[Tuple[str, ...], Any]] = [] self._flag_defs: List[Tuple[Tuple[str, ...], Any]] = []
self.show_targets = True self.show_targets = True
self._graph = Graph() self._graph = Graph()
self.rest = [] # remaining positional args
# global flags # global flags
self.dry = False self.dry = False
@ -568,8 +569,7 @@ def option(
def manage(version: bool = False) -> None: def manage(version: bool = False) -> None:
"""manage self""" """internal cli"""
print("self management stuff")
if version: if version:
print("current version", __version__) print("current version", __version__)
@ -712,8 +712,13 @@ def cli() -> None:
if len(sys.argv) == 1: if len(sys.argv) == 1:
parser.print_help(sys.stderr) parser.print_help(sys.stderr)
sys.exit(1) sys.exit(1)
elif "--" in sys.argv:
i = sys.argv.index("--")
args = vars(parser.parse_args(sys.argv[1:i]))
ctx.rest = sys.argv[i + 1 :]
else:
args = vars(parser.parse_args()) args = vars(parser.parse_args())
_ = args.pop("pos-arg", None) _ = args.pop("pos-arg", None)
ctx.verbose = args.pop("verbose", False) ctx.verbose = args.pop("verbose", False)
ctx.dry = args.pop("dry_run", False) ctx.dry = args.pop("dry_run", False)