From b0a798800750bc8a09e7fe8d947462721b63b202 Mon Sep 17 00:00:00 2001 From: woutersioen Date: Wed, 23 Jan 2019 11:00:54 +0100 Subject: [PATCH] Add command to list locales used in a project This way we can more easily download all locales in a cli script (fetch them using this command and then download in a loop) --- bin/onesky | 1 + src/ListLocaleCommand.php | 47 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/ListLocaleCommand.php diff --git a/bin/onesky b/bin/onesky index e29c4e9..9b2b96c 100755 --- a/bin/onesky +++ b/bin/onesky @@ -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(); diff --git a/src/ListLocaleCommand.php b/src/ListLocaleCommand.php new file mode 100644 index 0000000..3e2ce10 --- /dev/null +++ b/src/ListLocaleCommand.php @@ -0,0 +1,47 @@ +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('Empty OneSky response!'); + exit(1); + } + + $data = json_decode($response, true); + if (isset($data['meta']) && $data['meta']['status'] != 200) { + $output->writeln('' . $data['meta']['message'] . ''); + exit(1); + } + + foreach ($data['data'] as $language) { + $output->writeln($language['code']); + } + } +}