<?php declare(strict_types=1);
namespace Inhere\Console\Concern;
use Inhere\Console\Console;
use Inhere\Console\IO\Input;
use Inhere\Console\Contract\InputInterface;
use Inhere\Console\IO\Output;
use Inhere\Console\Contract\OutputInterface;
trait InputOutputAwareTrait
{
protected $input;
protected $output;
public function getScript(): string
{
return $this->input->getScript();
}
public function getScriptName(): string
{
return $this->input->getScriptName();
}
public function getCommandName(): string
{
return $this->input->getCommand();
}
public function getArg($name, $default = null)
{
return $this->input->getArg($name, $default);
}
public function getFirstArg(string $default = ''): string
{
return $this->input->getFirstArg($default);
}
public function getRequiredArg($name)
{
return $this->input->getRequiredArg($name);
}
public function getSameArg(array $names, $default = null)
{
return $this->input->getSameArg($names, $default);
}
public function getOpt($name, $default = null)
{
return $this->input->getOpt($name, $default);
}
public function getSameOpt(array $names, $default = null)
{
return $this->input->getSameOpt($names, $default);
}
public function getRequiredOpt(string $name, string $errMsg = '')
{
return $this->input->getRequiredOpt($name, $errMsg);
}
public function read(string $question = '', bool $nl = false): string
{
return $this->input->read($question, $nl);
}
public function write($message, $nl = true, $quit = false): int
{
return $this->output->write($message, $nl, $quit);
}
public function writeln($message, $quit = false): int
{
return $this->output->write($message, true, $quit);
}
public function getInput(): InputInterface
{
return $this->input;
}
public function setInput(InputInterface $input): void
{
$this->input = $input;
}
public function getOutput(): OutputInterface
{
return $this->output;
}
public function setOutput(OutputInterface $output): void
{
$this->output = $output;
}
public function getVerbLevel(): int
{
return (int)$this->input->getLongOpt('debug', Console::VERB_ERROR);
}
public function isDebug(int $level = Console::VERB_DEBUG): bool
{
return $level <= $this->getVerbLevel();
}
}