1 | <?php |
||
35 | class RemoteCommand extends BaseCommand |
||
36 | { |
||
37 | public const GIT_REMOTE = 'remote'; |
||
38 | public const GIT_REMOTE_OPTION_VERBOSE = '--verbose'; |
||
39 | public const GIT_REMOTE_OPTION_VERBOSE_SHORT = '-v'; |
||
40 | |||
41 | /** |
||
42 | * constructor |
||
43 | * |
||
44 | * @param \GitElephant\Repository $repo The repository object this command |
||
45 | * will interact with |
||
46 | */ |
||
47 | 13 | public function __construct(Repository $repo = null) |
|
48 | { |
||
49 | 13 | parent::__construct($repo); |
|
50 | 13 | } |
|
51 | |||
52 | /** |
||
53 | * Build the remote command |
||
54 | * |
||
55 | * NOTE: git-remote is most useful when using its subcommands, therefore |
||
56 | * in practice you will likely pass a SubCommandCommand object. This |
||
57 | * class provide "convenience" methods that do this for you. |
||
58 | * |
||
59 | * @param \GitElephant\Command\SubCommandCommand $subcommand A subcommand object |
||
60 | * @param array $options Options for the main git-remote command |
||
61 | * |
||
62 | * @throws \RuntimeException |
||
63 | * @return string Command string to pass to caller |
||
64 | */ |
||
65 | 13 | public function remote(SubCommandCommand $subcommand = null, array $options = []): string |
|
66 | { |
||
67 | 13 | $normalizedOptions = $this->normalizeOptions($options, $this->remoteCmdSwitchOptions()); |
|
68 | |||
69 | 13 | $this->clearAll(); |
|
70 | |||
71 | 13 | $this->addCommandName(self::GIT_REMOTE); |
|
72 | |||
73 | 13 | foreach ($normalizedOptions as $value) { |
|
74 | 3 | $this->addCommandArgument($value); |
|
75 | } |
||
76 | 13 | if ($subcommand !== null) { |
|
77 | 10 | $this->addCommandSubject($subcommand); |
|
78 | } |
||
79 | |||
80 | 13 | return $this->getCommand(); |
|
81 | } |
||
82 | |||
83 | /** |
||
84 | * Valid options for remote command that do not require an associated value |
||
85 | * |
||
86 | * @return array Associative array mapping all non-value options and their respective normalized option |
||
87 | */ |
||
88 | 13 | public function remoteCmdSwitchOptions(): array |
|
95 | |||
96 | /** |
||
97 | * git-remote --verbose command |
||
98 | * |
||
99 | * @throws \RuntimeException |
||
100 | * @return string |
||
101 | */ |
||
102 | 3 | public function verbose(): string |
|
106 | |||
107 | /** |
||
108 | * git-remote show [name] command |
||
109 | * |
||
110 | * NOTE: for technical reasons $name is optional, however under normal |
||
111 | * implementation it SHOULD be passed! |
||
112 | * |
||
113 | * @param string $name |
||
114 | * @param bool $queryRemotes |
||
115 | * |
||
116 | * @throws \RuntimeException |
||
117 | * @return string |
||
118 | */ |
||
119 | 3 | public function show($name = null, bool $queryRemotes = true): string |
|
126 | |||
127 | /** |
||
128 | * git-remote add [options] <name> <url> |
||
129 | * |
||
130 | * @param string $name remote name |
||
131 | * @param string $url URL of remote |
||
132 | * @param array $options options for the add subcommand |
||
133 | * |
||
134 | * @throws \RuntimeException |
||
135 | * @return string |
||
136 | */ |
||
137 | 8 | public function add($name, $url, $options = []): string |
|
144 | } |
||
145 |