Skip to content

Displaying name of created action #177

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

Merged
merged 5 commits into from
Sep 8, 2024
Merged
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
23 changes: 23 additions & 0 deletions config/deploy-operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,27 @@

'name' => env('DEPLOY_OPERATIONS_QUEUE_NAME'),
],

/*
|--------------------------------------------------------------------------
| Show
|--------------------------------------------------------------------------
|
| This option determines the display settings for various information messages.
|
*/

'show' => [
/*
|--------------------------------------------------------------------------
| Full Path
|--------------------------------------------------------------------------
|
| This parameter determines how exactly the link to the created file should
| be displayed - the full path to the file or a relative one.
|
*/

'full_path' => env('DEPLOY_OPERATIONS_SHOW_FULL_PATH', false),
],
];
5 changes: 5 additions & 0 deletions src/Helpers/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public function gitPath(): string
return base_path();
}

public function showFullPath(): bool
{
return (bool) $this->config->get('deploy-operations.show.full_path');
}

protected function directory(): string
{
return $this->config->get('deploy-operations.path', base_path('operations'));
Expand Down
39 changes: 30 additions & 9 deletions src/Processors/Make.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use DragonCode\Support\Facades\Filesystem\File;
use DragonCode\Support\Facades\Filesystem\Path;
use DragonCode\Support\Facades\Helpers\Str;
use DragonCode\Support\Helpers\Ables\Stringable;

use function base_path;
use function date;
Expand All @@ -21,34 +22,47 @@ class Make extends Processor

public function handle(): void
{
$this->notification->task('Creating an operation', fn () => $this->run());
$fullPath = $this->getFullPath();

$this->notification->task($this->message($fullPath), fn () => $this->create($fullPath));
}

protected function run(): void
protected function message(string $path): string
{
$name = $this->getName();
$path = $this->getPath();

$this->create($path . '/' . $name);
return 'Operation [' . $this->displayName($path) . '] created successfully';
}

protected function create(string $path): void
{
File::copy($this->stubPath(), $path);
}

protected function getName(): string
protected function displayName(string $path): string
{
$branch = $this->getBranchName();
return Str::of($path)
->when(! $this->showFullPath(), fn (Stringable $str) => $str->after(base_path()))
->replace('\\', '/')
->ltrim('./')
->toString();
}

return $this->getFilename($branch);
protected function getName(): string
{
return $this->getFilename(
$this->getBranchName()
);
}

protected function getPath(): string
{
return $this->options->path;
}

protected function getFullPath(): string
{
return $this->getPath() . $this->getName();
}

protected function getFilename(string $branch): string
{
$directory = Path::dirname($branch);
Expand All @@ -59,6 +73,8 @@ protected function getFilename(string $branch): string
->prepend($this->getTime())
->finish('.php')
->prepend($directory . '/')
->replace('\\', '/')
->ltrim('./')
->toString();
}

Expand Down Expand Up @@ -100,4 +116,9 @@ protected function stubPath(): string

return $this->defaultStub;
}

protected function showFullPath(): bool
{
return $this->config->showFullPath();
}
}