1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Cocotte\Machine; |
4
|
|
|
|
5
|
|
|
use Cocotte\Console\OptionProvider; |
6
|
|
|
use Cocotte\Console\Style; |
7
|
|
|
use Cocotte\Console\StyledInputOption; |
8
|
|
|
use Cocotte\Environment\EnvironmentState; |
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
10
|
|
|
use Symfony\Component\Console\Question\Question; |
11
|
|
|
|
12
|
|
|
class MachineNameOptionProvider implements OptionProvider |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var Style |
16
|
|
|
*/ |
17
|
|
|
private $style; |
18
|
|
|
|
19
|
|
|
public function __construct(Style $style) |
20
|
|
|
{ |
21
|
|
|
$this->style = $style; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function option(EnvironmentState $environmentState): InputOption |
25
|
|
|
{ |
26
|
|
|
return new StyledInputOption( |
27
|
|
|
$this->optionName(), |
28
|
|
|
null, |
29
|
|
|
InputOption::VALUE_REQUIRED, |
30
|
|
|
$this->helpMessage(), |
31
|
|
|
$environmentState->defaultValue(MachineName::MACHINE_NAME, MachineName::DEFAULT_VALUE) |
32
|
|
|
); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function helpMessage(): string |
36
|
|
|
{ |
37
|
|
|
return $this->style->optionHelp( |
38
|
|
|
"Machine Name", |
39
|
|
|
[ |
40
|
|
|
"This is both the name used for <info>docker-machine</info> commands and by Digital Ocean\nfor the droplet name. ". |
41
|
|
|
"Must match ".MachineName::REGEX, |
42
|
|
|
] |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function validate(string $value) |
47
|
|
|
{ |
48
|
|
|
MachineName::fromString($value); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function onCorrectAnswer(string $answer) |
52
|
|
|
{ |
53
|
|
|
// do nothing |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function optionName(): string |
57
|
|
|
{ |
58
|
|
|
return MachineName::OPTION_NAME; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function question(): Question |
62
|
|
|
{ |
63
|
|
|
return new Question( |
64
|
|
|
$this->style->quittableQuestion("Enter a <options=bold>Machine name</>"), |
65
|
|
|
MachineName::DEFAULT_VALUE |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
} |