Skip to content

Commit

Permalink
Merge pull request #177 from fkrzski/main
Browse files Browse the repository at this point in the history
Displaying name of created action
  • Loading branch information
andrey-helldar authored Sep 8, 2024
2 parents c83b5fc + eaa5ccf commit 499b88a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 9 deletions.
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();
}
}

0 comments on commit 499b88a

Please sign in to comment.