-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0952dc
commit 2694eba
Showing
14 changed files
with
219 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,127 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Artemeon\M2G\Command; | ||
|
||
use Artemeon\M2G\Config\ConfigReader; | ||
use Exception; | ||
use Symfony\Component\Console\Helper\QuestionHelper; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Question\Question; | ||
|
||
use function Termwind\render; | ||
|
||
abstract class Command extends \Symfony\Component\Console\Command\Command | ||
class Command extends \Artemeon\Console\Command | ||
{ | ||
protected InputInterface $input; | ||
protected OutputInterface $output; | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
final protected function header(): void | ||
{ | ||
$this->input = $input; | ||
$this->output = $output; | ||
|
||
return $this->handle(); | ||
} | ||
|
||
protected function arguments(): array | ||
{ | ||
return $this->input->getArguments(); | ||
} | ||
|
||
protected function argument(string $name) | ||
{ | ||
return $this->input->getArgument($name); | ||
} | ||
|
||
protected function options(): array | ||
{ | ||
return $this->input->getOptions(); | ||
} | ||
|
||
protected function option(string $name) | ||
{ | ||
return $this->input->getOption($name); | ||
} | ||
|
||
protected function header(): void | ||
{ | ||
$this->success( | ||
$this->output->write( | ||
' | ||
__ __ _ _ <comment>____</comment> ____ _ _ _ _ _ | ||
| \/ | __ _ _ __ | |_ (_) ___ <comment>|___ \ </comment> / ___|(_)| |_ | | | | _ _ | |__ | ||
| |\/| | / _` || \'_ \ | __|| |/ __| <comment>__) |</comment> | | _ | || __|| |_| || | | || \'_ \ | ||
__ __ _ _ <comment>____</comment> ____ _ _ _ _ _ | ||
| \/ | __ _ _ __ | |_ (_) ___ <comment>|___ \ </comment> / ___|(_)| |_ | | | | _ _ | |__ | ||
| |\/| | / _` || \'_ \ | __|| |/ __| <comment>__) |</comment> | | _ | || __|| |_| || | | || \'_ \ | ||
| | | || (_| || | | || |_ | |\__ \ <comment>/ __/</comment> | |_| || || |_ | _ || |_| || |_) | | ||
|_| |_| \__,_||_| |_| \__||_||___/ <comment>|_____|</comment> \____||_| \__||_| |_| \__,_||_.__/ | ||
' | ||
); | ||
} | ||
|
||
protected function ask(string $question, string $default = null, bool $hidden = false) | ||
{ | ||
/** @var QuestionHelper $helper */ | ||
$helper = $this->getHelper('question'); | ||
$trailingSpace = str_ends_with($question, ' ') ? '' : ' '; | ||
$question = new Question($question . $trailingSpace, $default); | ||
$question->setHidden($hidden); | ||
|
||
return $helper->ask($this->input, $this->output, $question); | ||
} | ||
|_| |_| \__,_||_| |_| \__||_||___/ <comment>|_____|</comment> \____||_| \__||_| |_| \__,_||_.__/ | ||
protected function secret(string $question, string $default = null) | ||
{ | ||
return $this->ask($question, $default, true); | ||
} | ||
|
||
protected function info(string $message) | ||
{ | ||
$this->output->writeln($message); | ||
} | ||
protected function error(string $message) | ||
{ | ||
render( | ||
<<<HTML | ||
<div class="my-1 ml-1 px-1 bg-red-400 text-white"> | ||
$message | ||
</div> | ||
HTML | ||
); | ||
} | ||
|
||
protected function success(string $message) | ||
{ | ||
$this->output->writeln("<info>$message</info>"); | ||
} | ||
|
||
protected function warn(string $message) | ||
{ | ||
render( | ||
<<<HTML | ||
<div class="ml-1 px-1 bg-yellow-500 text-gray-900"> | ||
<strong>! $message !</strong> | ||
</div> | ||
HTML | ||
' | ||
); | ||
} | ||
|
||
protected function checkConfig(): void | ||
final protected function checkConfig(): void | ||
{ | ||
$config = (new ConfigReader())->read(); | ||
|
||
if (!$config) { | ||
$this->info(''); | ||
$this->newLine(); | ||
$this->warn('You have not configured mantis2github yet'); | ||
$this->warn('Please run "mantis2github configure" to get started'); | ||
$this->info(''); | ||
$this->newLine(); | ||
|
||
exit(1); | ||
exit(self::INVALID); | ||
} | ||
} | ||
|
||
abstract protected function handle(): int; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.