add($command); } } if ($input !== null) $this->setInput($input); if ($output !== null) $this->setOutput($output); } function addLiteral($cmd): self { A::append_nn($this->cmds, $cmd); return $this; } function add($cmd): self { if ($cmd !== null) { if (!($cmd instanceof ICmd)) { shell::fix_cmd($cmd); } $this->cmds[] = $cmd; } return $this; } function setInput(?string $input=null): self { $this->input = $input; return $this; } function setOutput(?string $output=null): self { $this->output = $output; return $this; } function getCmd(?string $sep=null): string { if ($sep === null) $sep = "\n"; $actualCmd = []; A::append_nn($actualCmd, $this->getVars($sep)); $parts = []; foreach ($this->cmds as $cmd) { if ($cmd instanceof ICmd) { $cmd = "(".$cmd->getCmd($sep).")"; } $parts[] = $cmd; } $cmd = implode(" | ", $parts); $input = $this->input; $output = $this->output; if ($input !== null || $output !== null) { $parts = []; if ($input !== null) $parts[] = "<".escapeshellarg($input); $parts[] = $cmd; if ($output !== null) $parts[] = ">".escapeshellarg($output); $cmd = implode(" ", $parts); } A::append($actualCmd, $cmd); return implode($sep, $actualCmd); } }