Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
lotfio committed Jul 18, 2020
1 parent 97f5961 commit 2753b80
Show file tree
Hide file tree
Showing 24 changed files with 750 additions and 624 deletions.
96 changes: 46 additions & 50 deletions commands.php
Original file line number Diff line number Diff line change
@@ -1,79 +1,75 @@
<?php

/**
*
* @author <[email protected]>
* @package Conso PHP Console Creator
*
* @version 1.0.0
*
* @license MIT
*
* @category CLI
*
* @copyright 2019 Lotfio Lakehal
*/

$conso->command('--version', function($inp, $out, $app){

$out->writeLn("\n " . $app->getName() . " version " . $app->getVersion() . "\n", "yellow");

$conso->command('--version', function ($inp, $out, $app) {
$out->writeLn("\n ".$app->getName().' version '.$app->getVersion()."\n", 'yellow');
})->alias(['-v']);

$conso->command('--help', function($inp, $out, $app){

$out->writeLn("\nUsage: \n\n", 'yellow');
$out->writeLn(" command:subcommand [options] [-flags]\n\n");

$out->writeLn("Special flags: \n\n", 'yellow');

$flags = $inp->reservedFlags();
$out->writeLn(" " . $flags[0] . " ", 'green');
$out->writeLn(" " . $flags[1] . " \n", 'green');
$out->writeLn(" " . $flags[2] . " ", 'green');
$out->writeLn(" " . $flags[3] . " \n", 'green');
$out->writeLn(" " . $flags[4] . " ", 'green');
$out->writeLn(" " . $flags[5] . " \n", 'green');
$out->writeLn(" " . $flags[6] . " ", 'green');
$out->writeLn(" " . $flags[7] . " \n", 'green');
$out->writeLn(" " . $flags[8] . " ", 'green');
$out->writeLn( $flags[9] . " \n", 'green');
$out->writeLn(" " . $flags[10] . " ", 'green');
$out->writeLn(" " . $flags[11] . " \n", 'green');

$out->writeLn("\nHelp: \n\n", 'yellow');
$out->writeLn(" The help special flag displays help for a given command: \n\n");
$out->writeLn(" To display application version, please use the -v or --version special flags.\n");
$out->writeLn(" To display the list of available commands, please use the -c or --commands special flags.\n");
$out->writeLn(" To silent warning, please use the -q or --quiet special flags.\n");
$out->writeLn(" To disable ansi, please use the --no-ansi special flag.\n");

$conso->command('--help', function ($inp, $out, $app) {
$out->writeLn("\nUsage: \n\n", 'yellow');
$out->writeLn(" command:subcommand [options] [-flags]\n\n");

$out->writeLn("Special flags: \n\n", 'yellow');

$flags = $inp->reservedFlags();
$out->writeLn(' '.$flags[0].' ', 'green');
$out->writeLn(' '.$flags[1]." \n", 'green');
$out->writeLn(' '.$flags[2].' ', 'green');
$out->writeLn(' '.$flags[3]." \n", 'green');
$out->writeLn(' '.$flags[4].' ', 'green');
$out->writeLn(' '.$flags[5]." \n", 'green');
$out->writeLn(' '.$flags[6].' ', 'green');
$out->writeLn(' '.$flags[7]." \n", 'green');
$out->writeLn(' '.$flags[8].' ', 'green');
$out->writeLn($flags[9]." \n", 'green');
$out->writeLn(' '.$flags[10].' ', 'green');
$out->writeLn(' '.$flags[11]." \n", 'green');

$out->writeLn("\nHelp: \n\n", 'yellow');
$out->writeLn(" The help special flag displays help for a given command: \n\n");
$out->writeLn(" To display application version, please use the -v or --version special flags.\n");
$out->writeLn(" To display the list of available commands, please use the -c or --commands special flags.\n");
$out->writeLn(" To silent warning, please use the -q or --quiet special flags.\n");
$out->writeLn(" To disable ansi, please use the --no-ansi special flag.\n");
})->alias(['-h']);

$conso->command('--commands', function($inp, $out, $app){
$conso->command('--commands', function ($inp, $out, $app) {
// remove special commands
$commands = array_filter($app->getCommands(), function($elem){
if(strpos($elem['name'], '--') === FALSE) return $elem;
$commands = array_filter($app->getCommands(), function ($elem) {
if (strpos($elem['name'], '--') === false) {
return $elem;
}
});

if(count($commands) > 0)
{
if (count($commands) > 0) {
$out->writeLn("\nAvailable Commands: \n\n", 'yellow');

$max = max(array_map(function($elem){ return count($elem);}, $commands));
$max = max(array_map(function ($elem) { return count($elem); }, $commands));

foreach($commands as $command)
{
$out->writeLn(" ". $command['name'] . str_repeat(' ', ($max - strlen($command['name'])) + 4 ), 'green');
$out->writeLn($command['description'] . "\n");
foreach ($commands as $command) {
$out->writeLn(' '.$command['name'].str_repeat(' ', ($max - strlen($command['name'])) + 4), 'green');
$out->writeLn($command['description']."\n");
}

$out->writeLn("\n");
}

})->alias(['-c']);

$conso->command('--no-ansi', function($inp, $out, $app){
$conso->command('--no-ansi', function ($inp, $out, $app) {
$out->disableAnsi(); // disable ansi
$cm = explode(DIRECTORY_SEPARATOR, getcwd());
$cmd = ' php ' . $cm[count($cm) - 1];
$cm = explode(DIRECTORY_SEPARATOR, getcwd());
$cmd = ' php '.$cm[count($cm) - 1];
passthru($cmd);
});

$conso->command('command', 'Conso\\Commands\\Command');
$conso->command('command', 'Conso\\Commands\\Command');
48 changes: 27 additions & 21 deletions src/Conso/Command.php
Original file line number Diff line number Diff line change
@@ -1,68 +1,74 @@
<?php namespace Conso;
<?php

namespace Conso;

/**
*
* @author <[email protected]>
* @package Conso PHP Console Creator
*
* @version 1.0.0
*
* @license MIT
*
* @category CLI
*
* @copyright 2019 Lotfio Lakehal
*/

use Conso\Contracts\InputInterface;
use Conso\Contracts\OutputInterface;

/**
* This class is base command class
* This class is base command class.
*/
class Command
{
/**
* base constructor
* base constructor.
*
* @param InputInterface $input
* @param InputInterface $input
* @param OutputInterface $output
* @param Conso $app
* @param Conso $app
*/
public function __construct(InputInterface $input, OutputInterface $output, Conso $app)
{
if($input->flag(0) == '--no-ansi')
if ($input->flag(0) == '--no-ansi') {
$output->disableAnsi();
}

//if($input->flag(0) == '-q' || $input->flag(0) == '--quiet'); // if quiet flag

if($input->flag(0) == '-h' || $input->flag(0) == '--help')
if ($input->flag(0) == '-h' || $input->flag(0) == '--help') {
$this->displayCommandHelp($input, $output, $app);
}
}

/**
* display help for a given command
* display help for a given command.
*
* @param InputInterface $input
* @param InputInterface $input
* @param OutputInterface $output
* @param Conso $app
* @param Conso $app
*
* @return void
*/
protected function displayCommandHelp($input, $output, $app)
{
$name = $app->activeCommand['name'];
$help = $app->activeCommand['help'];

$output->writeLn("\n help for [" . $name . "] command:\n\n", "yellow");
$output->writeLn("\n help for [".$name."] command:\n\n", 'yellow');

$output->writeLn(" php conso $name:{sub command} {options}\n\n");

if(is_array($help) && count($help) > 0)
{
foreach($help as $key => $value)
{
$output->writeLn(" [". $key ."]\n\n", 'yellow');
if (is_array($help) && count($help) > 0) {
foreach ($help as $key => $value) {
$output->writeLn(' ['.$key."]\n\n", 'yellow');

foreach($value as $a => $b)
$output->writeLn(" " . $a . " : " . $b . "\n\n");
foreach ($value as $a => $b) {
$output->writeLn(' '.$a.' : '.$b."\n\n");
}
}
}
exit;
}
}
}
Loading

0 comments on commit 2753b80

Please sign in to comment.