Skip to content

Commit

Permalink
NEW Refactor CLI interaction with Silverstripe app
Browse files Browse the repository at this point in the history
- Turn sake into a symfony/console app
- Avoid using HTTPRequest for CLI interaction
- Implement abstract hybrid execution path
  • Loading branch information
GuySartorelli committed Aug 28, 2024
1 parent e3508d4 commit 942a93f
Show file tree
Hide file tree
Showing 33 changed files with 1,797 additions and 1,135 deletions.
14 changes: 6 additions & 8 deletions _config/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@
Name: DevelopmentAdmin
---
SilverStripe\Dev\DevelopmentAdmin:
commands:
build: 'SilverStripe\Dev\HybridExecution\Command\DevBuild'
'build:cleanup': 'SilverStripe\Dev\HybridExecution\Command\DevBuildCleanup'
'build:defaults': 'SilverStripe\Dev\HybridExecution\Command\DevBuildDefaults'
config: 'SilverStripe\Dev\HybridExecution\Command\DevConfig'
'config:audit': 'SilverStripe\Dev\HybridExecution\Command\DevConfigAudit'
registered_controllers:
build:
controller: SilverStripe\Dev\DevBuildController
links:
build: 'Build/rebuild this environment. Call this whenever you have updated your project sources'
tasks:
controller: SilverStripe\Dev\TaskRunner
links:
tasks: 'See a list of build tasks to run'
confirm:
controller: SilverStripe\Dev\DevConfirmationController
config:
controller: Silverstripe\Dev\DevConfigController
links:
config: 'View the current config, useful for debugging'

SilverStripe\Dev\CSSContentParser:
disable_xml_external_entities: true
4 changes: 2 additions & 2 deletions _config/extensions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ SilverStripe\Security\Member:
SilverStripe\Security\Group:
extensions:
- SilverStripe\Security\InheritedPermissionFlusher
SilverStripe\ORM\DatabaseAdmin:
SilverStripe\Dev\HybridExecution\Command\DevBuild:
extensions:
- SilverStripe\Dev\Validation\DatabaseAdminExtension
- SilverStripe\Dev\Validation\DevBuildExtension
21 changes: 21 additions & 0 deletions bin/sake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env php
<?php

use SilverStripe\Cli\Sake;

// Ensure that people can't access this from a web-server
if (!in_array(PHP_SAPI, ['cli', 'cgi', 'cgi-fcgi'])) {
echo 'sake cannot be run from a web request, you have to run it on the command-line.';
die();
}

require_once __DIR__ . '/../src/includes/autoload.php';

$sake = new Sake();
$sake->addCommands([
// probably do this inside the sake app itself though
// TODO:
// - flush
// - navigate (use HTTPRequest and spin off a "web" request from CLI)
]);
$sake->run();
35 changes: 0 additions & 35 deletions cli-script.php

This file was deleted.

9 changes: 4 additions & 5 deletions client/styles/debug.css
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ a:active {
}

/* Content types */
.build,
.options,
.trace {
position: relative;
Expand All @@ -128,19 +127,19 @@ a:active {
line-height: 1.3;
}

.build .success {
.options .success {
color: #2b6c2d;
}

.build .error {
.options .error {
color: #d30000;
}

.build .warning {
.options .warning {
color: #8a6d3b;
}

.build .info {
.options .info {
color: #0073c1;
}

Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
],
"bin": [
"sake"
"bin/sake"
],
"require": {
"php": "^8.3",
Expand All @@ -36,12 +36,14 @@
"psr/container": "^1.1 || ^2.0",
"psr/http-message": "^1",
"sebastian/diff": "^4.0",
"sensiolabs/ansi-to-html": "^1.2",
"silverstripe/config": "^3",
"silverstripe/assets": "^3",
"silverstripe/vendor-plugin": "^2",
"sminnee/callbacklist": "^0.1.1",
"symfony/cache": "^6.1",
"symfony/config": "^6.1",
"symfony/console": "^7.0",
"symfony/dom-crawler": "^6.1",
"symfony/filesystem": "^6.1",
"symfony/http-foundation": "^6.1",
Expand Down Expand Up @@ -85,6 +87,7 @@
},
"autoload": {
"psr-4": {
"SilverStripe\\Cli\\": "src/Cli/",
"SilverStripe\\Control\\": "src/Control/",
"SilverStripe\\Control\\Tests\\": "tests/php/Control/",
"SilverStripe\\Core\\": "src/Core/",
Expand Down
119 changes: 0 additions & 119 deletions sake

This file was deleted.

52 changes: 52 additions & 0 deletions src/Cli/ArrayCommandLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace SilverStripe\Cli;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
use Symfony\Component\Console\Exception\CommandNotFoundException;

/**
* Command loader that holds more command loaders
*/
class ArrayCommandLoader implements CommandLoaderInterface
{
/**
* @var array<CommandLoaderInterface>
*/
private array $loaders = [];

public function __construct(array $loaders)
{
$this->loaders = $loaders;
}

public function get(string $name): Command
{
foreach ($this->loaders as $loader) {
if ($loader->has($name)) {
return $loader->get($name);
}
}
throw new CommandNotFoundException("Can't find command $name");
}

public function has(string $name): bool
{
foreach ($this->loaders as $loader) {
if ($loader->has($name)) {
return true;
}
}
return false;
}

public function getNames(): array
{
$names = [];
foreach ($this->loaders as $loader) {
$names = array_merge($names, $loader->getNames());
}
return array_unique($names);
}
}
Loading

0 comments on commit 942a93f

Please sign in to comment.