1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Divergence package. |
4
|
|
|
* |
5
|
|
|
* (c) Henry Paradiz <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace Divergence\CLI\Controllers\Commands; |
11
|
|
|
|
12
|
|
|
use Divergence\CLI\Env; |
13
|
|
|
use Divergence\CLI\Command; |
14
|
|
|
use Divergence\CLI\ConfigWriter; |
15
|
|
|
use Divergence\CLI\Controllers\CommandLineHandler; |
16
|
|
|
|
17
|
|
|
class Config extends CommandLineHandler |
18
|
|
|
{ |
19
|
|
|
public static function handle() |
20
|
|
|
{ |
21
|
|
|
switch ($action = static::shiftArgs()) { |
|
|
|
|
22
|
|
|
case 'database': |
23
|
|
|
static::database(); |
24
|
|
|
break; |
25
|
|
|
|
26
|
|
|
default: |
27
|
|
|
Basics::usage(); |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public static function error($error) |
32
|
|
|
{ |
33
|
|
|
Command::$climate->error($error); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public static function database() |
37
|
|
|
{ |
38
|
|
|
$climate = Command::$climate; |
39
|
|
|
|
40
|
|
|
try { |
41
|
|
|
$configs = Env::getConfig(getcwd(), 'db'); |
42
|
|
|
} catch (\Exception $e) { |
43
|
|
|
$climate->shout('No database config found! Are you sure this is a project folder?'); |
44
|
|
|
return; |
45
|
|
|
} |
46
|
|
|
$labels = array_keys($configs); |
47
|
|
|
|
48
|
|
|
if (!$label = static::shiftArgs()) { |
49
|
|
|
$input = $climate->radio('Choose a config to reconfigure:', $labels); |
50
|
|
|
$response = $input->prompt(); |
51
|
|
|
dump($configs[$response]); |
52
|
|
|
if (in_array($response, $labels)) { |
53
|
|
|
static::wizardAndSave($response, $configs[$response]); |
54
|
|
|
} |
55
|
|
|
} else { |
56
|
|
|
if (in_array($label, $labels)) { |
57
|
|
|
static::wizardAndSave($label, $configs[$label]); |
58
|
|
|
} else { |
59
|
|
|
$climate->yellow('No database config found with that label.'); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public static function wizardAndSave($label, $config) |
65
|
|
|
{ |
66
|
|
|
$climate = Command::$climate; |
67
|
|
|
$config = Database::wizard($config); |
68
|
|
|
$input = $climate->confirm('Save this config?'); |
69
|
|
|
$input->defaultTo('y'); |
70
|
|
|
if ($input->confirmed()) { |
71
|
|
|
ConfigWriter::configWriter($label, $config); |
72
|
|
|
} |
73
|
|
|
return $config; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|