Skip to content

Commit 98a804a

Browse files
author
Caneco
committed
First release
1 parent 02e1001 commit 98a804a

15 files changed

+762
-3
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 Caneco
3+
Copyright (c) 2019 Vitor Caneco
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 232 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,232 @@
1-
# artisan-aliases
2-
Save keystrokes and run Artisan commands your way
1+
<p align="center"><img src="https://raw.githubusercontent.com/caneco/artisan-aliases/master/art/logo.png" width="400"/></p>
2+
3+
<p align="center"><img src="https://raw.githubusercontent.com/caneco/artisan-aliases/master/art/preview.png"/></p>
4+
5+
<p align="center">
6+
<a href="https://packagist.org/packages/caneco/artisan-aliases"><img src="https://poser.pugx.org/caneco/artisan-aliases/d/total.svg" alt="Total Downloads"></a>
7+
<a href="https://packagist.org/packages/caneco/artisan-aliases"><img src="https://poser.pugx.org/caneco/artisan-aliases/v/stable.svg" alt="Latest Stable Version"></a>
8+
<a href="https://packagist.org/packages/caneco/artisan-aliases"><img src="https://poser.pugx.org/caneco/artisan-aliases/license.svg" alt="License"></a>
9+
</p>
10+
11+
---
12+
13+
# Laravel Artisan Aliases
14+
15+
If you live in the command it's always good to save some keystrokes, specially for commands that you keep typing. This package will help you create alias for you artisan commands, and more..
16+
17+
18+
19+
## Installation
20+
21+
You can install the package via composer:
22+
23+
```
24+
>_ composer require caneco/artisan-aliases
25+
```
26+
27+
#### Registering the service provider
28+
In Laravel 5.5 the service provider will automatically get registered. But if needed just add the service provider in `config/app.php` file:
29+
30+
```
31+
'providers' => [
32+
// ...
33+
Caneco\ArtisanAliases\ArtisanAliasesServiceProvider::class,
34+
];
35+
```
36+
37+
#### Publishing the package assets
38+
To publish the configuration file and `.laravel_alias`, execute the following command and pick this Service Provider:
39+
40+
```
41+
>_ php artisan vendor:publish
42+
43+
Which provider or tag's files would you like to publish?:
44+
[0 ] Publish files from all providers and tags listed below
45+
[1 ] Provider: Caneco\ArtisanAliasesExample:
46+
[… ] ...
47+
```
48+
49+
Or do it in a single command:
50+
51+
```
52+
>_ php artisan vendor:publish --provider="Caneco\ArtisanAliases\ArtisanAliasesServiceProvider"
53+
```
54+
55+
When published, this is the contents of the config file:
56+
57+
```PHP
58+
return [
59+
60+
/*
61+
|--------------------------------------------------------------------------
62+
| Artisan Alias Master Switch
63+
|--------------------------------------------------------------------------
64+
| This option may be used to enable/disable all Artisan alias
65+
| defined in your local or global `.laravel_alias` file
66+
*/
67+
'enabled' => env('ARTISAN_ALIAS_ENABLED', true),
68+
69+
/*
70+
|--------------------------------------------------------------------------
71+
| Default Alias File
72+
|--------------------------------------------------------------------------
73+
| This option allows you to have three ways of load the list of alias. The
74+
| `global` option will only load the alias defined in your home directory,
75+
| while the `local` option, will limit the alias from the list in your
76+
| application. Finally, The `both` option, or anything else, will
77+
| load the alias from both locations.
78+
|
79+
| Supported: "global", "local", "both",
80+
*/
81+
'use_only' => 'both',
82+
83+
];
84+
```
85+
86+
87+
88+
89+
## Usage
90+
91+
After publishing the initial files, your alias will be stored folder locally in the application directory; or globally in your home directory. And like any other bash alias file the contents will have following format:
92+
93+
```
94+
laravel="inspire"
95+
# cc="clear-compiled"
96+
```
97+
98+
#### Listing existing alias
99+
To list the current alias available you can run the following command:
100+
101+
```
102+
>_ php artisan alias --list
103+
Laravel `Artisan Aliases` 1.0.0
104+
105+
Usage:
106+
alias [-g|--global] [--] [<as>]
107+
108+
Available alias:
109+
laravel inspire
110+
cc clear-compiled
111+
```
112+
113+
Also, the available alias in appear on your artisan command list:
114+
115+
```
116+
$ php artisan list
117+
...
118+
Available commands:
119+
alias Create an alias of another command
120+
cc * Alias for the `clear-compiled` command
121+
clear-compiled Remove the compiled class file
122+
down Put the application into maintenance mode
123+
...
124+
inspire Display an inspiring quote
125+
laravel * Alias for the `inspire` command
126+
list Lists commands
127+
...
128+
```
129+
130+
131+
#### Adding new alias
132+
Add your alias directly in the file `.laravel_alias`, or just use the artisan command:
133+
134+
```
135+
>_ php artisan alias laravel "inspire"
136+
```
137+
138+
And, if you pass the `--global` option the alias will be registered instead in the `.laravel_alias` of your home directory.
139+
140+
```
141+
>_ php artisan alias cc="clear-compiled" --global
142+
```
143+
144+
If you dont pass the required arguments the `--list` option will be triggered, and you will be presented with the command info; usage; and list of alias available.
145+
146+
#### Comments
147+
Anything after the character `#` it's considered a comment and will be not considered for execution.
148+
149+
```
150+
# https://twitter.com/davidhemphill/status/1083466919964041217
151+
migrate:make="make:migration" # DOPE
152+
```
153+
154+
#### Quote surrounding
155+
Surrounding the command with quotes are not mandatory, but if the command to be aliased has some spaces you must use them.
156+
157+
#### Multiple commands
158+
An alias can have multiple commands associated by using the operators `&&` or `||`. And, just like bash, when using `&&` the sequence of the commands will terminate if one of them returns a value bigger than zero. While the `||` will continue no matter what.
159+
160+
```
161+
# EXAMPLE
162+
163+
tables-up=notifications:table && queue:table && queue:failed-table && ...
164+
```
165+
166+
#### Shell commands
167+
If you prefix your alias with an exclamation point, will be treated as a shell command.
168+
169+
#### Alias*ception…*
170+
Yes, you can also create alias of alias...
171+
172+
#### Artisan groups
173+
If you set your alias with a namespace like `boot:tables` or `boot:cache`, Artisan list will group your alias toghether.
174+
175+
```
176+
# EXAMPLE
177+
178+
boot
179+
boot:cache * Alias for the `config:cache || route:cache || view:cache command`
180+
boot:tables * Alias for the `cache:table || notifications:table || queue:failed-table || queue:table || session:table command`
181+
```
182+
183+
184+
185+
186+
## Gotchas ⚠️
187+
188+
- Currently, to modify or delete any alias you need to open the `.laravel_aliases` and do it manually but it's planned to have a way of doing from the terminal.
189+
- Adding an alias with the same name as other it will result with an exception.
190+
- Having two alias manually defined in the `.laravel_aliases` the last alias command will prevail.
191+
- An alias with the same name as an Artisan command, the Artisan prevail.
192+
193+
194+
195+
196+
## Supported versions
197+
198+
Look at the table below to find out what versions of Laravel are supported on what version of this package:
199+
200+
Laravel Framework | Artisan Alias
201+
:--- | :---
202+
`5.7.*` | `^1.0`
203+
204+
205+
206+
207+
## Road map
208+
209+
Artisan Alias was released so you can use it normally, but there's still some things that I would like to see in the package.
210+
211+
Here's the plan for what's coming:
212+
213+
- [ ] Remove an existing alias using the option `--d|delete`
214+
- [ ] Allow to replace an existing alias using the option `--force`
215+
- [ ] Firing a `@handle` method if
216+
- [ ] Alert the user try to add an alias with `sudo` in the command **(usefull?)**
217+
- [ ] Add comments
218+
- [ ] Add tests
219+
220+
221+
222+
223+
## Contributing
224+
225+
All contributions (pull requests, issues and feature requests) are welcome. Make sure to read through the [Contributing file](/caneco/artisan-alias/blob/master/CONTRIBUTING.md) first, though. See the [contributors page](/caneco/artisan-aliases/graphs/contributors) for all contributors.
226+
227+
228+
229+
230+
## License
231+
232+
The MIT License (MIT). Please see [License File](/caneco/artisan-alias/blob/master/LICENSE.md) for more information.

composer.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "caneco/artisan-aliases",
3+
"description": "Save keystrokes and run Artisan commands your way",
4+
"keywords": [
5+
"laravel",
6+
"artisan",
7+
"cli",
8+
"alias",
9+
"aliases"
10+
],
11+
"license": "MIT",
12+
"authors": [
13+
{
14+
"name": "Caneco",
15+
"email": "[email protected]"
16+
}
17+
],
18+
"require": {
19+
"php": "^7.1",
20+
"sixlive/dotenv-editor": "^1.1"
21+
},
22+
"require-dev": {
23+
"larapack/dd": "^1.0",
24+
"orchestra/testbench": "^3.7",
25+
"sempro/phpunit-pretty-print": "^1.0",
26+
"phpunit/phpunit": "^6.0|^7.0"
27+
},
28+
"autoload": {
29+
"psr-4": {
30+
"Caneco\\ArtisanAliases\\": "src/"
31+
}
32+
},
33+
"autoload-dev": {
34+
"psr-4": {
35+
"Caneco\\ArtisanAliases\\Tests\\": "tests/"
36+
}
37+
},
38+
"scripts": {
39+
"test": "phpunit"
40+
},
41+
"config": {
42+
"sort-packages": true
43+
},
44+
"extra": {
45+
"laravel": {
46+
"providers": [
47+
"Caneco\\ArtisanAliases\\ArtisanAliasesServiceProvider"
48+
]
49+
}
50+
}
51+
}

config/aliases.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Artisan Alias Master Switch
8+
|--------------------------------------------------------------------------
9+
| This option may be used to enable/disable all Artisan alias
10+
| defined in your local or global `.laravel_alias` file
11+
*/
12+
'enabled' => env('ARTISAN_ALIAS_ENABLED', true),
13+
14+
/*
15+
|--------------------------------------------------------------------------
16+
| Default Alias File
17+
|--------------------------------------------------------------------------
18+
| This option allows you to have three ways of load the list of alias. The
19+
| `global` option will only load the alias defined in your home directory,
20+
| while the `local` option, will limit the alias from the list in your
21+
| application. Finally, The `both` option, or anything else, will
22+
| load the alias from both locations.
23+
|
24+
| Supported: "global", "local", "both",
25+
*/
26+
'use_only' => 'both',
27+
28+
];

phpunit.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
verbose="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false"
12+
printerClass="Sempro\PHPUnitPrettyPrinter\PrettyPrinter">
13+
<testsuites>
14+
<testsuite name="ArtisanAliases Test Suite">
15+
<directory>tests</directory>
16+
</testsuite>
17+
</testsuites>
18+
<filter>
19+
<whitelist>
20+
<directory suffix=".php">src/</directory>
21+
</whitelist>
22+
</filter>
23+
</phpunit>

src/Alias.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Caneco\ArtisanAliases;
4+
5+
use Caneco\ArtisanAliases\AliasFile;
6+
use Caneco\ArtisanAliases\AliasManager;
7+
8+
class Alias
9+
{
10+
public const VERSION = '1.0.0';
11+
12+
public static function store(string $name, string $line, bool $global)
13+
{
14+
$manager = new AliasManager(
15+
$global ? AliasFile::global() : AliasFile::local()
16+
);
17+
18+
return $manager->save(new AliasModel($name, $line));
19+
}
20+
21+
public static function load(?string $location = null): array
22+
{
23+
switch ($location) {
24+
case 'local':
25+
return self::local();
26+
case 'global':
27+
return self::global();
28+
default:
29+
return array_merge(self::global(), self::local());
30+
}
31+
}
32+
33+
public static function local(): array
34+
{
35+
return (new AliasManager(
36+
AliasFile::local()
37+
))->load();
38+
}
39+
40+
public static function global(): array
41+
{
42+
return (new AliasManager(
43+
AliasFile::global()
44+
))->load();
45+
}
46+
}

0 commit comments

Comments
 (0)