diff --git a/config/deploy-operations.php b/config/deploy-operations.php index 84b7cbf4..8c44461b 100644 --- a/config/deploy-operations.php +++ b/config/deploy-operations.php @@ -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), + ], ]; diff --git a/src/Helpers/Config.php b/src/Helpers/Config.php index 4425baf7..ab3298cb 100644 --- a/src/Helpers/Config.php +++ b/src/Helpers/Config.php @@ -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')); diff --git a/src/Processors/Make.php b/src/Processors/Make.php index 77635268..2b77bad4 100644 --- a/src/Processors/Make.php +++ b/src/Processors/Make.php @@ -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; @@ -21,15 +22,14 @@ 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 @@ -37,11 +37,20 @@ 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 @@ -49,6 +58,11 @@ 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); @@ -59,6 +73,8 @@ protected function getFilename(string $branch): string ->prepend($this->getTime()) ->finish('.php') ->prepend($directory . '/') + ->replace('\\', '/') + ->ltrim('./') ->toString(); } @@ -100,4 +116,9 @@ protected function stubPath(): string return $this->defaultStub; } + + protected function showFullPath(): bool + { + return $this->config->showFullPath(); + } }