mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-23 13:45:45 -05:00
exec/cmd: generate_cmd_{su,elevated}: tolerate flat string as input for cmd instead of list
This commit is contained in:
parent
ac7d16e4a7
commit
4dc134c8f8
1 changed files with 5 additions and 2 deletions
|
@ -47,15 +47,18 @@ def wrap_in_bash(cmd: Union[list[str], str], flatten_result=True) -> Union[str,
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
def generate_cmd_elevated(cmd: list[str], elevation_method: ElevationMethod):
|
def generate_cmd_elevated(cmd: Union[list[str], str], elevation_method: ElevationMethod):
|
||||||
"wraps `cmd` in the necessary commands to escalate, e.g. `['sudo', '--', cmd]`."
|
"wraps `cmd` in the necessary commands to escalate, e.g. `['sudo', '--', cmd]`."
|
||||||
|
if isinstance(cmd, str):
|
||||||
|
cmd = wrap_in_bash(cmd, flatten_result=False)
|
||||||
|
assert not isinstance(cmd, str) # typhints cmd as list[str]
|
||||||
if elevation_method not in ELEVATION_METHODS:
|
if elevation_method not in ELEVATION_METHODS:
|
||||||
raise Exception(f"Unknown elevation method {elevation_method}")
|
raise Exception(f"Unknown elevation method {elevation_method}")
|
||||||
return ELEVATION_METHODS[elevation_method] + cmd
|
return ELEVATION_METHODS[elevation_method] + cmd
|
||||||
|
|
||||||
|
|
||||||
def generate_cmd_su(
|
def generate_cmd_su(
|
||||||
cmd: list[str],
|
cmd: Union[list[str], str],
|
||||||
switch_user: str,
|
switch_user: str,
|
||||||
elevation_method: Optional[ElevationMethod] = None,
|
elevation_method: Optional[ElevationMethod] = None,
|
||||||
force_su: bool = False,
|
force_su: bool = False,
|
||||||
|
|
Loading…
Add table
Reference in a new issue