|
9 | 9 | use Diffy\Screenshot; |
10 | 10 | use DiffyCli\Config; |
11 | 11 | use GuzzleHttp\Exception\InvalidArgumentException; |
| 12 | +use GuzzleHttp\Utils; |
12 | 13 | use Robo\Tasks; |
13 | 14 | use Symfony\Component\Console\Style\SymfonyStyle; |
14 | | - |
15 | | -use function GuzzleHttp\json_decode; |
| 15 | +use Symfony\Component\Yaml\Yaml; |
16 | 16 |
|
17 | 17 | class ProjectCommand extends Tasks |
18 | 18 | { |
@@ -41,7 +41,11 @@ private function isValidJsonConfig(string $configurationPath): array |
41 | 41 | } |
42 | 42 |
|
43 | 43 | try { |
44 | | - return json_decode($configuration, true); |
| 44 | + if (str_ends_with($configurationPath, '.yaml')) { |
| 45 | + return Yaml::parse($configuration, true); |
| 46 | + } |
| 47 | + |
| 48 | + return Utils::jsonDecode($configuration, true); |
45 | 49 | } catch (InvalidArgumentException $exception) { |
46 | 50 | $this->getIO()->writeln('<error>Configuration is not valid JSON<error>'); |
47 | 51 |
|
@@ -171,21 +175,25 @@ public function createCompare( |
171 | 175 | } |
172 | 176 |
|
173 | 177 | /** |
174 | | - * Update single project configuration |
| 178 | + * Update single project configuration from YAML file |
175 | 179 | * |
176 | 180 | * @command project:update |
177 | 181 | * |
178 | 182 | * @param int $projectId Id of the project. |
179 | | - * @param string $configurationPath Path to the json config file. |
| 183 | + * @param string $configurationPath Path to the YAML config file. |
180 | 184 | * |
181 | | - * @usage project:update 342 ./examples/diffy_update_project.json |
182 | | - * Updates given project ID with the diffy config. |
| 185 | + * @usage project:update 342 ./examples/diffy_update_project.yaml |
| 186 | + * Configuration can be downloaded from Project's settings page. |
183 | 187 | * |
184 | 188 | * @throws InvalidArgumentException |
185 | 189 | */ |
186 | 190 | public function updateProject(int $projectId, string $configurationPath) |
187 | 191 | { |
188 | | - Project::update($projectId, $this->isValidJsonConfig($configurationPath)); |
| 192 | + if (str_ends_with($configurationPath, '.yaml')) { |
| 193 | + Project::updateYaml($projectId, $this->isValidJsonConfig($configurationPath)); |
| 194 | + } else { |
| 195 | + Project::update($projectId, $this->isValidJsonConfig($configurationPath)); |
| 196 | + } |
189 | 197 |
|
190 | 198 | $this->getIO()->writeln('Project <info>' . $projectId . '</info> updated.'); |
191 | 199 | } |
|
0 commit comments