lib.ExecContext: Support bytes-typed cmd_input

The Input instance passed as cmd_input to ExecContext.run() and
.sudo() currently may be of type str. Allow to pass bytes, too.

At the same time, disallow None to be passed as cmd_input. Force the
caller to be more explicit how it wants input to be handled, notably
with respect to interactivity.

Along the way fix a bug: Content in cmd_input should result in
CallContext.interactive == False but doesn't. Fix that.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-04-15 14:02:44 +02:00
commit 04b294917f
9 changed files with 46 additions and 29 deletions

View file

@ -15,6 +15,7 @@ from urllib.parse import urlparse
from enum import Enum, auto
from .log import *
from .ExecContext import InputMode
class AskpassKey(Enum):
Username = auto()
@ -40,7 +41,7 @@ async def run_cmd(*args, ec: ExecContext|None=None, verbose: bool|None=None, int
ec = Local(verbose_default=verbose, interactive=interactive)
return await ec.run(verbose=verbose, *args, **kwargs)
async def run_curl(args: list[str], parse_json: bool=False, wd=None, throw=None, verbose=None, cmd_input=None, ec: ExecContext|None=None, decode=False) -> dict|str: # export
async def run_curl(args: list[str], parse_json: bool=False, wd=None, throw=None, verbose=None, cmd_input=InputMode.NonInteractive, ec: ExecContext|None=None, decode=False) -> dict|str: # export
if verbose is None:
verbose = False if ec is None else ec.verbose_default
cmd = ['curl']