Skip to content

Commit

Permalink
Add command to list locales used in a project
Browse files Browse the repository at this point in the history
This way we can more easily download all locales in a cli script (fetch
them using this command and then download in a loop)
  • Loading branch information
WouterSioen committed Jan 23, 2019
1 parent 241286b commit b0a7988
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions bin/onesky
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ $application->add(new Teamleader\OneSky\InitCommand());
$application->add(new Teamleader\OneSky\UploadCommand());
$application->add(new Teamleader\OneSky\DownloadCommand());
$application->add(new Teamleader\OneSky\MergeCommand());
$application->add(new Teamleader\OneSky\ListLocaleCommand());
$application->run();
47 changes: 47 additions & 0 deletions src/ListLocaleCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Teamleader\OneSky;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class ListLocaleCommand extends Command
{
protected function configure()
{
parent::configure();
$this
->setName('list-locale')
->setDescription('List the locale enabled in the project');
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$this->initializeClient($input->getOption('key'), $input->getOption('secret'));

$project_id = $input->getOption('project_id');
if (is_null($project_id)) {
$project_id = $this->config['project_id'];
}

$response = $this->client->projects('languages', [
'project_id' => $project_id,
]);

if (!$response) {
$output->writeln('<error>Empty OneSky response!</error>');
exit(1);
}

$data = json_decode($response, true);
if (isset($data['meta']) && $data['meta']['status'] != 200) {
$output->writeln('<error>' . $data['meta']['message'] . '</error>');
exit(1);
}

foreach ($data['data'] as $language) {
$output->writeln($language['code']);
}
}
}

0 comments on commit b0a7988

Please sign in to comment.