Commit 4f68e8d9 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Add a new proc.Executor 'subcommand' method

parent 3e561110
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ from __future__ import annotations

import io
import sys
from copy import copy
from os import PathLike
from os import fspath
from os import write as fdwrite
@@ -174,6 +175,7 @@ class Executor(list[Argument]):
	"""

	T = TypeVar("T")
	E = TypeVar("E", bound="Executor")

	def __init__(self, *cmd: Argument):
		self[:] = cmd
@@ -277,3 +279,15 @@ class Executor(list[Argument]):
		Override to amend command arguments and kwargs for exec_io() prior to execution
		"""
		return cmd

	def subcommand(self: E, *args: Argument) -> E:
		"""
		Return a new Executor instance of the same class with additional arguments appended

		The returned instance is created as a shallow copy; if attribute values need to be
		copied, subclasses must implement __copy__().
		(see https://docs.python.org/3/library/copy.html)
		"""
		new = copy(self)
		new.extend(args)
		return new