dais-shell 0.1.10__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: dais-shell
3
- Version: 0.1.10
3
+ Version: 0.2.0
4
4
  Summary: The shell tool for Dais.
5
5
  Author: BHznJNs
6
6
  Author-email: BHznJNs <441768875@qq.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "dais-shell"
3
- version = "0.1.10"
3
+ version = "0.2.0"
4
4
  description = "The shell tool for Dais."
5
5
  readme = "README.md"
6
6
  authors = [{ name = "BHznJNs", email = "441768875@qq.com" }]
@@ -1,4 +1,5 @@
1
1
  import asyncio
2
+ import shlex
2
3
  import shutil
3
4
  from dataclasses import asdict, dataclass
4
5
 
@@ -15,7 +16,7 @@ class BashCommandStep(CommandStep):
15
16
  return cls(**asdict(step))
16
17
 
17
18
  def to_wrapper_script(self):
18
- return 'exec "$1" "${@:2}"'
19
+ return f"exec {shlex.quote(self.command)} {self.args}"
19
20
 
20
21
  # --- --- --- --- --- ---
21
22
 
@@ -36,21 +37,13 @@ class BashRuntime(BaseShellRuntime):
36
37
  self._shell,
37
38
  "-c",
38
39
  step.to_wrapper_script(),
39
- "--",
40
- step.command,
41
- *step.args
42
40
  ]
43
41
 
44
42
  def _prepare_cmd(self, step: CommandStep) -> list[str]:
45
43
  env_expander = EnvExpander(step.env or {})
46
- step.args = [env_expander.expand(arg) for arg in step.args]
44
+ step.args = env_expander.expand(step.args)
47
45
  step = BashCommandStep.from_command_step(step)
48
- resolved = shutil.which(step.command)
49
- is_shell_command = resolved is None
50
- if is_shell_command:
51
- return self._make_bash_commands(step)
52
- else:
53
- return [resolved, *step.args]
46
+ return self._make_bash_commands(step)
54
47
 
55
48
  def run_sync(self,
56
49
  step: CommandStep,
@@ -20,19 +20,9 @@ class PowerShellCommandStep(CommandStep):
20
20
  return cls(**asdict(step))
21
21
 
22
22
  def to_wrapper_script(self):
23
-
24
23
  def ps_quote(s: str) -> str:
25
24
  return "'" + s.replace("'", "''") + "'"
26
25
 
27
- def fmt_arg(s: str) -> str:
28
- return s if re.match(r"^-[a-zA-Z]", s) else ps_quote(s)
29
-
30
- def ps_encode(s: str) -> str:
31
- return base64.b64encode(s.encode("utf-8")).decode("ascii")
32
-
33
- args_str = (" " + " ".join(fmt_arg(a) for a in self.args)) if self.args else ""
34
- invocation = f"& {ps_quote(self.command)}{args_str}"
35
-
36
26
  script = f"""
37
27
  $ErrorActionPreference = "Stop"
38
28
  $PSNativeCommandArgumentPassing = "Standard"
@@ -42,7 +32,10 @@ $OutputEncoding = [System.Text.Encoding]::UTF8
42
32
  [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
43
33
  [Console]::InputEncoding = [System.Text.Encoding]::UTF8
44
34
 
45
- {invocation}
35
+ $command = {ps_quote(self.command)}
36
+
37
+ & $command {self.args}
38
+
46
39
  exit $LASTEXITCODE"""
47
40
  return script.strip()
48
41
 
@@ -111,7 +104,7 @@ class PowerShellRuntime(BaseShellRuntime):
111
104
 
112
105
  def _prepare_cmd(self, step: CommandStep) -> list[str]:
113
106
  env_expander = EnvExpander(step.env or {})
114
- step.args = [env_expander.expand(arg) for arg in step.args]
107
+ step.args = env_expander.expand(step.args)
115
108
  step = PowerShellCommandStep.from_command_step(step)
116
109
  script = step.to_wrapper_script()
117
110
  encoded = self._encode(script)
@@ -8,7 +8,7 @@ from .exceptions import ForbiddenShellTargetError
8
8
  @dataclass
9
9
  class CommandStep:
10
10
  command: str
11
- args: list[str]
11
+ args: str
12
12
  cwd: str | Path
13
13
  env: dict[str, str] | None = None
14
14
  timeout: int | None = None
File without changes