File tree Expand file tree Collapse file tree 4 files changed +56
-1
lines changed
Expand file tree Collapse file tree 4 files changed +56
-1
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,24 @@ class CreateUserCommand extends Command
151151}
152152```
153153
154+ By default, the command name's prefix is ` app: ` . You can override with your own
155+ prefix (or none at all):
156+
157+ ``` php
158+ use Symfony\Component\Console\Command\Command;
159+ use Zenstruck\Console\AutoName;
160+
161+ class CreateUserCommand extends Command
162+ {
163+ use AutoName; // command's name will be "create-user"
164+
165+ protected static function autoNamePrefix(): string
166+ {
167+ return '';
168+ }
169+ }
170+ ```
171+
154172### ` ConfigureWithAttributes `
155173
156174Use this trait to use the ` Argument ` and ` Option ` attributes to configure your command's
Original file line number Diff line number Diff line change @@ -29,8 +29,16 @@ public static function getDefaultName(): string
2929 ->snake ()
3030 ->replace ('_ ' , '- ' )
3131 ->beforeLast ('-command ' )
32- ->prepend (' app: ' )
32+ ->prepend (static :: autoNamePrefix () )
3333 ->toString ()
3434 ;
3535 }
36+
37+ /**
38+ * Override to set your own prefix (or none).
39+ */
40+ protected static function autoNamePrefix (): string
41+ {
42+ return 'app: ' ;
43+ }
3644}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Zenstruck \Console \Tests \Fixture \Command ;
4+
5+ use Symfony \Component \Console \Command \Command ;
6+ use Zenstruck \Console \AutoName ;
7+
8+ /**
9+ * @author Kevin Bond <kevinbond@gmail.com>
10+ */
11+ final class AutoNameNoPrefixCommand extends Command
12+ {
13+ use AutoName;
14+
15+ protected static function autoNamePrefix (): string
16+ {
17+ return '' ;
18+ }
19+ }
Original file line number Diff line number Diff line change 66use Symfony \Component \Console \Command \Command ;
77use Zenstruck \Console \AutoName ;
88use Zenstruck \Console \Tests \Fixture \Command \AutoNameCommand ;
9+ use Zenstruck \Console \Tests \Fixture \Command \AutoNameNoPrefixCommand ;
910
1011/**
1112 * @author Kevin Bond <kevinbond@gmail.com>
@@ -21,6 +22,15 @@ public function generates_name_automatically(): void
2122 $ this ->assertSame ('app:auto-name ' , (new AutoNameCommand ())->getName ());
2223 }
2324
25+ /**
26+ * @test
27+ */
28+ public function can_remove_prefix (): void
29+ {
30+ $ this ->assertSame ('auto-name-no-prefix ' , AutoNameNoPrefixCommand::getDefaultName ());
31+ $ this ->assertSame ('auto-name-no-prefix ' , (new AutoNameNoPrefixCommand ())->getName ());
32+ }
33+
2434 /**
2535 * @test
2636 */
You can’t perform that action at this time.
0 commit comments