8000 WIP Presets work by mattstauffer · Pull Request #185 · tighten/lambo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

WIP Presets work #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions app/Actions/DisplayHelpScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,31 @@

namespace App\Actions;

use App\GeneratesHelpScreens;
use App\Options;

class DisplayHelpScreen
{
use LamboAction;

protected $indent = 30;
use LamboAction, GeneratesHelpScreens;

protected $commands = [
'help-screen' => 'Display this screen',
'help-screen' => 'Display this screen', // @todo modify to mention you can ask for help on a specific item
'edit-config' => 'Edit config file',
'edit-after' => 'Edit "after" file',
];

public function __invoke()
{

$this->line("\n<comment>Usage:</comment>");
$this->line(" lambo new myApplication [arguments]\n");
$this->line(" lambo myApplication [arguments]\n");
$this->line("<comment>Commands (lambo COMMANDNAME):</comment>");

foreach ($this->commands as $command => $description) {
$spaces = $this->makeSpaces(strlen($command));
$this->line(" <info>{$command}</info>{$spaces}{$description}");
}

$this->line("\n<comment>Options (lambo new myApplication OPTIONS):</comment>");
$this->line("\n<comment>Options (lambo myApplication OPTIONS):</comment>");

foreach ((new Options)->all() as $option) {
$this->line($this->createCliStringForOption($option));
Expand Down
53 changes: 53 additions & 0 deletions app/Actions/DisplaySpecificHelpScreen.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace App\Actions;

use App\GeneratesHelpScreens;
use Illuminate\Support\Str;

class DisplaySpecificHelpScreen
{
use LamboAction, GeneratesHelpScreens;

public function __invoke($target)
{
// @todo pass it to the correct render method
$this->renderPresetHelp($target, $this->getObjectForTarget($target));
}

public function getObjectForTarget($target)
{
// if command existss with this target, then get it
// if option exists for this target, get it
// if preset exists for this target, get it
$studly = Str::studly($target);
// If this exists as a preset class, new it up
return app(\App\Presets\Premade\Telescope::class);
}

public function renderCommandHelp($target)
{
$this->line("<comment>Description:</comment>");
$this->line(" Description for {$target} here.\n");
$this->line("<comment>Usage:</comment>");
$this->line(" lambo {$target} @todo do they take params");

$this->renderOptions();
}

public function renderOptionHelp()
{
// @todo
}

public function renderPresetHelp($target, $preset)
{
// @todo allow for defining the params
$this->line("<comment>Description:</comment>");
$this->line(" " . $preset->description . "\n");
$this->line("<comment>Usage:</comment>");
$this->line(" lambo myApplication --presets=\"{$target}\"");

$this->renderOptions();
}
}
89 changes: 89 additions & 0 deletions app/Actions/RunPresets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace App\Actions;

use App\InteractsWithLamboConfig;
use App\Presets\BasePreset;
use App\Shell\Shell;
use Illuminate\Support\Str;
use stdClass;

class RunPresets
{
use LamboAction, InteractsWithLamboConfig;

public $presets = []; // Array of stdClass objects, each with "preset" and "parameters" keys
protected $shell;

public function __construct(Shell $shell)
{
$this->presets = $this->presetsPassed();
$this->shell = $shell;
}

public function presetsPassed()
{
return collect(explode('|', config('lambo.store.presets')))
->filter()
->map(function ($preset) {
$parameters = Str::contains($preset, ':')
? explode(',', Str::after($preset, ':'))
: [];

return (object) [
'preset' => Str::before($preset, ':'),
'parameters' => $parameters,
];
})->toArray();
}

public function __invoke()
{
foreach ($this->presets as $passedPreset) {
// construct
$preset = $this->getPresetInstance($passedPreset);

// run before
$preset->baseBefore();

// run run
$preset->baseRun();

// run after
$preset->baseAfter();

$this->commitToGit($passedPreset->preset);
}
}

public function getPresetInstance(stdClass $preset): BasePreset
{
$className = $this->getPresetClassName($preset->preset);

// look for the pre-made class
$fqcn = "App\\Presets\\Premade\\{$className}";

if (class_exists($fqcn)) {
return app($fqcn, ['params' => $preset->parameters]);
}

throw new \Exception('Cannot resolve preset: ' . $shortName);

// look for the hand-made local
// @todo something like "custom/telescope"

// look for the composer-loaded class
// @todo something like "nunomaduro/telescope"
}

public function getPresetClassName(string $presetShortName): string
{
return Str::studly($presetShortName);
}

public function commitToGit(string $presetName)
{
$this->shell->execInProject('git add .');
$this->shell->execInProject("git commit -m \"Run ${presetName} preset.\"");
}
}
3 changes: 3 additions & 0 deletions app/Actions/SetConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SetConfig
const CREATE_DATABASE = 'CREATE_DATABASE';
const FULL = 'FULL';
const WITH_OUTPUT = 'WITH_OUTPUT';
const PRESETS = 'PRESETS';

public $keys = [
self::PROJECTPATH,
Expand All @@ -50,6 +51,7 @@ class SetConfig
self::DB_PASSWORD,
self::FULL,
self::WITH_OUTPUT,
self::PRESETS,
];

const FRONTEND_FRAMEWORKS = [
Expand Down Expand Up @@ -92,6 +94,7 @@ public function __invoke()
'browser' => $this->getOptionValue('browser', self::BROWSER),
'frontend' => $this->getFrontendType(),
'full' => $this->getBooleanOptionValue('full'),
'presets' => $this->getOptionValue('presets'),
]);
}

Expand Down
13 changes: 10 additions & 3 deletions app/Commands/HelpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use App\Actions\DisplayHelpScreen;
use App\Actions\DisplayLamboWelcome;
use App\Actions\DisplaySpecificHelpScreen;
use LaravelZero\Framework\Commands\Command;

class HelpCommand extends Command
{
protected $signature = 'help-screen';
protected $signature = 'help-screen {target?}';
protected $description = 'Show help';

public function handle()
Expand All @@ -17,7 +18,13 @@ public function handle()
return $this;
});

app(DisplayLamboWelcome::class)();
app(DisplayHelpScreen::class)();
if (! $this->argument('target')) {
app(DisplayLamboWelcome::class)();
app(DisplayHelpScreen::class)();

return;
}

app(DisplaySpecificHelpScreen::class)($this->argument('target'));
}
}
5 changes: 4 additions & 1 deletion app/Commands/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use App\Actions\OpenInEditor;
use App\Actions\RunAfterScript;
use App\Actions\RunLaravelInstaller;
use App\Actions\RunPresets;
use App\Actions\SetConfig;
use App\Actions\ValetLink;
use App\Actions\ValetSecure;
Expand All @@ -40,7 +41,7 @@ public function buildSignature()
{
return collect((new Options)->all())->reduce(function ($carry, $option) {
return $carry . $this->buildSignatureOption($option);
}, "new\n{projectName? : Name of the Laravel project}");
}, "{projectName? : Name of the Laravel project}");
}

public function buildSignatureOption($option)
Expand Down Expand Up @@ -90,6 +91,8 @@ public function handle()

app(InitializeGitRepo::class)();

app(RunPresets::class)();

app(InstallNpmDependencies::class)();

app(CompileAssets::class)();
Expand Down
38 changes: 38 additions & 0 deletions app/GeneratesHelpScreens.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App;

trait GeneratesHelpScreens
{
protected $indent = 30;

public function makeSpaces($count)
{
return str_repeat(" ", $this->indent - $count);
}

public function renderOptions()
{
$this->line("\n<comment>Options:</comment>");
$this->line(" <info>Todo</info> Options coming soon");
/* @todo
foreach ($options as $option) {
return " <info>{$flag}</info>{$spaces}{$description}";
}
*/
}

public function genericOptions()
{
/*
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--env[=ENV] The environment the command should run under
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
*/
}
}
5 changes: 5 additions & 0 deletions app/Options.php
6F23
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class Options
'param_description' => 'PATH',
'cli_description' => "Customize the path in which the new project will be created",
],
[
'long' => 'presets',
'param_description' => 'A:1,2|B|C',
'cli_description' => "Call preset(s), optionally with parameters",
],
[
'short' => 'b',
'long' => 'browser',
Expand Down
Loading
0