Skip to content

Commit

Permalink
Add show option --show (all|config|runtime|connection|database|migrat…
Browse files Browse the repository at this point in the history
…ion)
  • Loading branch information
roberto-butti committed Jun 1, 2020
1 parent 5cc8788 commit 54a148b
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.1.6 - 2020-06-01

### Add

* Add show option --show (all|config|runtime|connection|database|migration)

## 0.1.5 - 2020-05-29

### Improve
Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ https://packagist.org/packages/hi-folks/lara-lens
php artisan laralens:diagnostic
```

### Usage: control database connection
You can see Database Connection information, and you can choose the table to check, and the column used for the "order by" (default created_at):
```sh
php artisan laralens:diagnostic --table=migrations --column-sort=id
Expand All @@ -51,6 +52,29 @@ To take the last **updated** user:
php artisan laralens:diagnostic --table=users --column-sort=updated_at
```

### Usage: control the output
You can control the output via the _show_ option. You can define:

* config
* connection
* database
* runtime
* migration
* all
The defalut for _--show_ option is _all_.


```sh
php artisan laralens:diagnostic --show=config --show=connection --show=database --show=runtime --show=migration
```

If you want to see only database information:

```sh
php artisan laralens:diagnostic --show=database
```


### Testing

``` bash
Expand Down
60 changes: 47 additions & 13 deletions src/Console/LaraLensCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class LaraLensCommand extends Command
{op=overview : What you want to see, overview or allconfigs}
{--table=users : name of the table, default users}
{--column-sort=created_at : column name used for sorting}
{--skip-connection : skip the connection testing}
{--show=*all : show (all|config|runtime|connection|database|migration)}
{--width-label='.self::DEFAULT_WIDTH.' : width of column for label}
{--width-value='.self::DEFAULT_WIDTH.' : width of column for value}
';
Expand All @@ -26,6 +26,14 @@ class LaraLensCommand extends Command
protected $widthLabel=self::DEFAULT_WIDTH;
protected $widthValue=self::DEFAULT_WIDTH;

public const OPTION_SHOW_NONE= 0b0000000;
public const OPTION_SHOW_CONFIGS= 0b0000001;
public const OPTION_SHOW_RUNTIMECONFIGS= 0b00000010;
public const OPTION_SHOW_CONNECTIONS= 0b00000100;
public const OPTION_SHOW_DATABASE= 0b00001000;
public const OPTION_SHOW_MIGRATION= 0b00010000;
public const OPTION_SHOW_ALL = 0b00011111;

private function allConfigs()
{
$this->info(json_encode(config()->all(), JSON_PRETTY_PRINT));
Expand Down Expand Up @@ -88,31 +96,57 @@ private function print_output(array $headers, array $rows)
}
}

private function overview($checkTable = "users", $columnSorting = "created_at")
private function overview($checkTable = "users", $columnSorting = "created_at", $show= self::OPTION_SHOW_ALL)
{
$ll = new LaraLens();
$output = $ll->getConfigs();
$this->print_output(["Config key via config()", "Values"], $output->toArray());
$output = $ll->getRuntimeConfigs();
$this->print_output(["Runtime Configs", "Values"], $output->toArray());
$output = $ll->getConnections();
$this->print_output(["Connections", "Values"], $output->toArray());
$output = $ll->getDatabase($checkTable, $columnSorting);
$this->print_output(["Database", "Values"], $output->toArray());
$this->call('migrate:status');
if ($show & self::OPTION_SHOW_CONFIGS)
{
$output = $ll->getConfigs();
$this->print_output(["Config key via config()", "Values"], $output->toArray());
}
if ($show & self::OPTION_SHOW_RUNTIMECONFIGS) {
$output = $ll->getRuntimeConfigs();
$this->print_output(["Runtime Configs", "Values"], $output->toArray());
}
if ($show & self::OPTION_SHOW_CONNECTIONS) {
$output = $ll->getConnections();
$this->print_output(["Connections", "Values"], $output->toArray());
}
if ($show & self::OPTION_SHOW_DATABASE) {
$output = $ll->getDatabase($checkTable, $columnSorting);
$this->print_output(["Database", "Values"], $output->toArray());
}
if ($show & self::OPTION_SHOW_MIGRATION) {
$this->call('migrate:status');
}
}



public function handle()
{
$op = $this->argument("op");
$checkTable = $this->option("table");
$columnSorting = $this->option("column-sort");
$skipConnection= $this->option("skip-connection");
$showOptions= $this->option("show");
if (is_array($showOptions)) {
if (count($showOptions) >0) {
$show = self::OPTION_SHOW_NONE;
$show = (in_array("all", $showOptions)) ? $show | self::OPTION_SHOW_ALL : $show ;
$show = (in_array("config", $showOptions)) ? $show | self::OPTION_SHOW_CONFIGS : $show ;
$show = (in_array("runtime", $showOptions)) ? $show | self::OPTION_SHOW_RUNTIMECONFIGS : $show ;
$show = (in_array("connection", $showOptions)) ? $show | self::OPTION_SHOW_CONNECTIONS : $show ;
$show = (in_array("database", $showOptions)) ? $show | self::OPTION_SHOW_DATABASE : $show ;
$show = (in_array("migration", $showOptions)) ? $show | self::OPTION_SHOW_MIGRATION : $show ;
} else {
$show = self::OPTION_SHOW_ALL;
}
}
$this->widthLabel= $this->option("width-label");
$this->widthValue= $this->option("width-value");
switch ($op) {
case 'overview':
$this->overview($checkTable, $columnSorting);
$this->overview($checkTable, $columnSorting, $show);
break;
case 'allconfigs':
$this->allConfigs();
Expand Down

0 comments on commit 54a148b

Please sign in to comment.