Skip to content

Commit cecf607

Browse files
committed
Add rename operation
1 parent 496f3a8 commit cecf607

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/Models/Installable.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Installable
99
{
1010
public string $name = '';
1111
public string $handle = '';
12+
public string $singularName = '';
1213
public string $path = '';
1314
public array $operations = [];
1415

@@ -22,6 +23,7 @@ public function __construct(array $config)
2223
{
2324
$this->name = $config['name'];
2425
$this->handle = $config['handle'];
26+
$this->singularName = $config['singular_name'] ?? '';
2527
$this->path = $config['path'];
2628
$this->operations = $config['operations'];
2729
}

src/Operations/Rename.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Studio1902\PeakCommands\Operations;
4+
5+
use Illuminate\Support\Str;
6+
use Studio1902\PeakCommands\Models\Installable;
7+
use function Laravel\Prompts\text;
8+
9+
class Rename extends Operation
10+
{
11+
12+
public function __construct(array $config)
13+
{
14+
}
15+
16+
public function run(): Installable
17+
{
18+
$this->installable->rename = true;
19+
$this->installable->renameName = text(
20+
label: "What should be the collection name for '{$this->installable->name}'?",
21+
placeholder: "E.g. '{$this->installable->name}'",
22+
required: true
23+
);
24+
25+
$this->installable->renameHandle = Str::slug($this->installable->renameName, '_');
26+
27+
$this->installable->renameSingularName = ucfirst(text(
28+
label: "What is the singular name for this '{$this->installable->renameName}' collection?",
29+
placeholder: "E.g. '{$this->installable->singularName}'",
30+
required: true
31+
));
32+
33+
$this->installable->renameSingularHandle = Str::slug($this->installable->renameSingularName, '_');
34+
35+
return $this->installable;
36+
}
37+
}

0 commit comments

Comments
 (0)