Skip to content

Commit 499b88a

Browse files
Merge pull request #177 from fkrzski/main
Displaying name of created action
2 parents c83b5fc + eaa5ccf commit 499b88a

File tree

3 files changed

+58
-9
lines changed

3 files changed

+58
-9
lines changed

config/deploy-operations.php

+23
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,27 @@
123123

124124
'name' => env('DEPLOY_OPERATIONS_QUEUE_NAME'),
125125
],
126+
127+
/*
128+
|--------------------------------------------------------------------------
129+
| Show
130+
|--------------------------------------------------------------------------
131+
|
132+
| This option determines the display settings for various information messages.
133+
|
134+
*/
135+
136+
'show' => [
137+
/*
138+
|--------------------------------------------------------------------------
139+
| Full Path
140+
|--------------------------------------------------------------------------
141+
|
142+
| This parameter determines how exactly the link to the created file should
143+
| be displayed - the full path to the file or a relative one.
144+
|
145+
*/
146+
147+
'full_path' => env('DEPLOY_OPERATIONS_SHOW_FULL_PATH', false),
148+
],
126149
];

src/Helpers/Config.php

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public function gitPath(): string
5151
return base_path();
5252
}
5353

54+
public function showFullPath(): bool
55+
{
56+
return (bool) $this->config->get('deploy-operations.show.full_path');
57+
}
58+
5459
protected function directory(): string
5560
{
5661
return $this->config->get('deploy-operations.path', base_path('operations'));

src/Processors/Make.php

+30-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use DragonCode\Support\Facades\Filesystem\File;
88
use DragonCode\Support\Facades\Filesystem\Path;
99
use DragonCode\Support\Facades\Helpers\Str;
10+
use DragonCode\Support\Helpers\Ables\Stringable;
1011

1112
use function base_path;
1213
use function date;
@@ -21,34 +22,47 @@ class Make extends Processor
2122

2223
public function handle(): void
2324
{
24-
$this->notification->task('Creating an operation', fn () => $this->run());
25+
$fullPath = $this->getFullPath();
26+
27+
$this->notification->task($this->message($fullPath), fn () => $this->create($fullPath));
2528
}
2629

27-
protected function run(): void
30+
protected function message(string $path): string
2831
{
29-
$name = $this->getName();
30-
$path = $this->getPath();
31-
32-
$this->create($path . '/' . $name);
32+
return 'Operation [' . $this->displayName($path) . '] created successfully';
3333
}
3434

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

40-
protected function getName(): string
40+
protected function displayName(string $path): string
4141
{
42-
$branch = $this->getBranchName();
42+
return Str::of($path)
43+
->when(! $this->showFullPath(), fn (Stringable $str) => $str->after(base_path()))
44+
->replace('\\', '/')
45+
->ltrim('./')
46+
->toString();
47+
}
4348

44-
return $this->getFilename($branch);
49+
protected function getName(): string
50+
{
51+
return $this->getFilename(
52+
$this->getBranchName()
53+
);
4554
}
4655

4756
protected function getPath(): string
4857
{
4958
return $this->options->path;
5059
}
5160

61+
protected function getFullPath(): string
62+
{
63+
return $this->getPath() . $this->getName();
64+
}
65+
5266
protected function getFilename(string $branch): string
5367
{
5468
$directory = Path::dirname($branch);
@@ -59,6 +73,8 @@ protected function getFilename(string $branch): string
5973
->prepend($this->getTime())
6074
->finish('.php')
6175
->prepend($directory . '/')
76+
->replace('\\', '/')
77+
->ltrim('./')
6278
->toString();
6379
}
6480

@@ -100,4 +116,9 @@ protected function stubPath(): string
100116

101117
return $this->defaultStub;
102118
}
119+
120+
protected function showFullPath(): bool
121+
{
122+
return $this->config->showFullPath();
123+
}
103124
}

0 commit comments

Comments
 (0)