Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit be3a6a0

Browse files
committed
Added Autocomplete trait with generic complete function and use it on all commands
1 parent f559533 commit be3a6a0

38 files changed

Lines changed: 112 additions & 76 deletions

load-application.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,25 @@
55

66
define( 'TEAM51_CLI_ROOT_DIR', __DIR__ );
77
if ( getenv( 'TEAM51_CONTRACTOR' ) ) { // Add the contractor flag automatically if set through the environment.
8-
$argv[] = '-c';
9-
$_SERVER['argv'][] = '-c';
8+
$argv[] = '-con';
9+
$_SERVER['argv'][] = '-con';
1010
}
1111

1212
require __DIR__ . '/vendor/autoload.php';
13-
require __DIR__ . '/src/helpers/config-loader.php';
13+
14+
// If one the arguments is --help or an auto-complete flag, skip the config-loader to avoid communicating with 1Pass
15+
$requires_auth = true;
16+
foreach( $argv as $arg ) {
17+
if ( in_array( $arg, ['_complete', '-h', '--help'], true ) ) {
18+
$requires_auth = false;
19+
break;
20+
}
21+
}
22+
23+
if ( $requires_auth ) {
24+
require __DIR__ . '/src/helpers/config-loader.php';
25+
}
26+
1427

1528
$application = new Application();
1629

src/commands/add-branch-protection-rules.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Symfony\Component\Console\Output\OutputInterface;
1010

1111
class Add_Branch_Protection_Rules extends Command {
12+
use \Team51\Helper\Autocomplete;
13+
1214
protected static $defaultName = 'add-branch-protection-rules';
1315

1416
protected function configure() {

src/commands/create-development-site.php

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
use Symfony\Component\Console\Input\InputInterface;
1010
use Symfony\Component\Console\Output\OutputInterface;
1111
use Symfony\Component\Console\Helper\ProgressBar;
12-
use Symfony\Component\Console\Completion\CompletionInput;
13-
use Symfony\Component\Console\Completion\CompletionSuggestions;
1412
use Team51\Helper\Pressable_Connection_Helper;
1513
use function Team51\Helper\get_pressable_site_by_id;
1614
use function Team51\Helper\get_pressable_site_sftp_user_by_email;
1715
use function Team51\Helper\run_app_command;
1816
use function Team51\Helper\run_pressable_site_wp_cli_command;
1917

2018
class Create_Development_Site extends Command {
19+
use \Team51\Helper\Autocomplete;
20+
2121
protected static $defaultName = 'create-development-site';
2222

2323
protected function configure() {
@@ -31,28 +31,6 @@ protected function configure() {
3131
->addOption( 'branch', null, InputOption::VALUE_REQUIRED, "The GitHub branch you would like to the development site to use. Defaults to 'develop'." );
3232
}
3333

34-
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void {
35-
$args = $input->getArguments();
36-
$arg_keys = array_keys($args);
37-
foreach( $arg_keys as $arg ) {
38-
if ( ! in_array($arg, [ 'command' ]) ) {
39-
$arg = '[' . $arg . ']';
40-
$suggestions->suggestValue( $arg );
41-
}
42-
}
43-
44-
$options = $input->getOptions();
45-
$opt_keys = array_keys($options);
46-
foreach( $opt_keys as $opt ) {
47-
if ( ! in_array($opt, ['ansi', 'contractor', 'help', 'no-interaction', 'version', 'verbose', 'quiet', 'dev']) ) {
48-
$opt = '--' . $opt;
49-
$suggestions->suggestValue( $opt );
50-
}
51-
}
52-
53-
$suggestions->suggestValue( 'Example: team51 create-development-site --siteid=123 --label=issue-1234 --temporary-clone --skip-safety-net --branch=feature-branch' . PHP_EOL );
54-
}
55-
5634
protected function execute( InputInterface $input, OutputInterface $output ) {
5735
$api_helper = new API_Helper();
5836

src/commands/create-production-site.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use function Team51\Helper\run_app_command;
1212

1313
class Create_Production_Site extends Command {
14+
use \Team51\Helper\Autocomplete;
15+
1416
protected static $defaultName = 'create-production-site';
1517

1618
const DEPLOYHQ_ZONE_EUROPE = 3; // UK

src/commands/create-repository.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
* CLI command for creating a new GitHub repository.
2828
*/
2929
class Create_Repository extends Command {
30+
use \Team51\Helper\Autocomplete;
31+
3032
// region FIELDS AND CONSTANTS
3133

3234
/**

src/commands/delete-branch-protection-rules.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Symfony\Component\Console\Output\OutputInterface;
1010

1111
class Delete_Branch_Protection_Rules extends Command {
12+
use \Team51\Helper\Autocomplete;
13+
1214
protected static $defaultName = 'delete-branch-protection-rules';
1315

1416
protected function configure() {

src/commands/deployhq-rotate-private-key.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* CLI command for rotating private key in projects.
1313
*/
1414
final class DeployHQ_Rotate_Private_Key extends Command {
15+
use \Team51\Helper\Autocomplete;
16+
1517
/**
1618
* {@inheritdoc}
1719
*/

src/commands/dump-commands.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Symfony\Component\Console\Descriptor\XmlDescriptor;
1212

1313
class Dump_Commands extends Command {
14+
use \Team51\Helper\Autocomplete;
1415

1516
protected function configure() {
1617
$this

src/commands/flickr-scrap-photostream.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323
class Flickr_Scrap_Photostream extends Command {
2424
// region FIELDS AND CONSTANTS
25+
use \Team51\Helper\Autocomplete;
2526

2627
/**
2728
* {@inheritdoc}

src/commands/jetpack-enable-sso.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Symfony\Component\Console\Output\OutputInterface;
1010

1111
class Jetpack_Enable_SSO extends Command {
12+
use \Team51\Helper\Autocomplete;
13+
1214
protected static $defaultName = 'jetpack-enable-sso';
1315

1416
protected function configure() {

0 commit comments

Comments
 (0)