Skip to content

Commit

Permalink
Add CLI for creating new component. (#762)
Browse files Browse the repository at this point in the history
* Add CLI for creating new component.

* Add step for CONTRIBUTING.md file

* Update component CLI based on feedback

* Update component CLI

* Fix issues

* Add badges to generated README

* Add gRPC and protobuf notice to README
  • Loading branch information
jdpedrie authored and dwsupplee committed Jan 17, 2018
1 parent d57d551 commit cafafda
Show file tree
Hide file tree
Showing 18 changed files with 1,675 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dev/google-cloud
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

require __DIR__ . '/../vendor/autoload.php';

use Google\Cloud\Dev\AddComponent\Command\AddComponent;
use Google\Cloud\Dev\DocGenerator\Command\Docs;
use Google\Cloud\Dev\Release\Command\Release;
use Google\Cloud\Dev\Split\Command\Split;
Expand All @@ -35,4 +36,5 @@ $app = new Application;
$app->add(new Release(__DIR__));
$app->add(new Docs(__DIR__));
$app->add(new Split(__DIR__));
$app->add(new AddComponent(__DIR__));
$app->run();
179 changes: 179 additions & 0 deletions dev/src/AddComponent/Command/AddComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<?php
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Google\Cloud\Dev\AddComponent\Command;

use Google\Cloud\Dev\AddComponent\Composer;
use Google\Cloud\Dev\AddComponent\Contributing;
use Google\Cloud\Dev\AddComponent\Info;
use Google\Cloud\Dev\AddComponent\License;
use Google\Cloud\Dev\AddComponent\Manifest;
use Google\Cloud\Dev\AddComponent\QuestionTrait;
use Google\Cloud\Dev\AddComponent\Readmes;
use Google\Cloud\Dev\AddComponent\TableOfContents;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Question\Question;

/**
* Add a Component
*/
class AddComponent extends Command
{
use QuestionTrait;

private $cliBasePath;
private $templatesPath;

private $input;
private $output;

public function __construct($cliBasePath)
{
$this->cliBasePath = $cliBasePath;

parent::__construct();
}

protected function configure()
{
$this->setName('component')
->setDescription('Add a Component');
}

protected function execute(InputInterface $input, OutputInterface $output)
{
// this is gross.
$this->input = $input;
$this->output = $output;

$formatter = $this->getHelper('formatter');

$info = (new Info(
$this->getHelper('question'),
$input,
$output,
$this->cliBasePath
))->run();

$output->writeln($formatter->formatSection(
'License',
'Creating LICENSE file by copying from repository base.'
));

(new License($this->cliBasePath, $info['path']))->run();

$output->writeln($formatter->formatSection(
'Contributing',
'Creating CONTRIBUTING.md file by copying from template.'
));

(new Contributing($this->cliBasePath, $info['path']))->run();

$output->writeln($formatter->formatSection(
'Readme',
'Every directory which contains documented classes should contain a README file. ' .
'README files are populated using information you already supplied. ' .
'When a directory does not contain a single entry point, or a main client class, ' .
'README functions as a main service. In certain cases, README files are not ' .
'desirable. In clients with GAPICs, the `Gapic` and `resources` folders generally should not ' .
'include READMEs, because the Gapic client is documented in the parent class.' .
PHP_EOL
));

$readme = new Readmes(
$this->getHelper('question'),
$input,
$output,
$this->cliBasePath,
$info
);
$readme->run();

$output->writeln($formatter->formatSection(
'Table of Contents',
'The main service for a directory is what users will see when they first ' .
'encounter an endpoint in the documentation hierarchy. If a main service ' .
'is present (as in handwritten clients), that service should be used. ' .
'If not, choose README.md' .
PHP_EOL
));

(new TableOfContents(
$this->getHelper('formatter'),
$this->getHelper('question'),
$input,
$output,
$this->cliBasePath,
$info['path']
))->run($info['name']);

$output->writeln($formatter->formatSection(
'Table of Contents',
'Wrote table of contents data.' . PHP_EOL
));

$output->writeln($formatter->formatSection(
'Composer',
'The following questions allow us to properly configure the new component ' .
'for use with PHP\'s package manager, Composer.'
));

(new Composer(
$this->getHelper('question'),
$input,
$output,
$this->cliBasePath,
$info
))->run();

$output->writeln($formatter->formatSection(
'Docs Manifest',
'Finally, we need to configure the manifest for the documentation site.'
));

(new Manifest(
$this->getHelper('question'),
$input,
$output,
$this->cliBasePath,
$info
))->run();

$output->writeln('');
$output->writeln('');
$output->writeln('Success!');
}

protected function questionHelper()
{
return $this->getHelper('question');
}

protected function input()
{
return $this->input;
}

protected function output()
{
return $this->output;
}
}
46 changes: 46 additions & 0 deletions dev/src/AddComponent/ComponentTypeTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Google\Cloud\Dev\AddComponent;

/**
* Trait for choosing component type.
*/
trait ComponentTypeTrait
{
private $types = [
'gapic' => 'Generated Client only',
'veneer' => 'Handwritten veneer only',
'gapic-grpc' => 'Both generated and handwritten, but only generated supports gRPC',
'both-grpc' => 'Both generated and handwritten, and both clients support gRPC'
];

private function getComponentTypesListValues()
{
return array_values($this->types);
}

private function getComponentTypeKey($value)
{
return array_search($value, $this->types);
}

private function getComponentTypeValue($key)
{
return $this->types[$key];
}
}
Loading

0 comments on commit cafafda

Please sign in to comment.