Skip to content

Instantly share code, notes, and snippets.

@ichikaway
Created June 21, 2016 05:45
Show Gist options
  • Save ichikaway/1831c54a690310bc8c2cdea1d7ac7f07 to your computer and use it in GitHub Desktop.
Save ichikaway/1831c54a690310bc8c2cdea1d7ac7f07 to your computer and use it in GitHub Desktop.
app/Console/Commands/SampleCmd.php
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class SampleCmd extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'sample:command1 {user?}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//引数
$name = $this->argument('user');
if($name === null) {
//入力待ち
$name = $this->ask('What is your name?');
}
$this->info('hello, ' . $name);
//yes / no 選択
if (!$this->confirm('Do you love BEER? [y|N]')) {
$this->error('ERROR. EXIT.');
fputs(STDERR, 'ERROR');
return 1;
}
//選択リスト表示、選択
$beerChoice = null;
while($beerChoice !== 'IPA') {
$beerChoice = $this->choice('What kind?', ['Lager', 'IPA', 'Wheat', 'Pale Ale'], false);
}
//テーブル
$header = ['Beer', 'Price'];
$contents = [
['PunkIPA', 650],
['Jack Hammer', 700],
['帝国IPA', 600],
['StoneIPA', 1000]
];
$this->table($header, $contents);
//プログレスバー
if ($this->confirm('Drink? [y|N]')) {
system('say "Let\'s drink"');
$bar = $this->output->createProgressBar( count($contents) );
foreach($contents as $beer) {
$bar->advance();
sleep(1);
}
$this->info(' Congrats!');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment