Skip to content

Commit

Permalink
First release
Browse files Browse the repository at this point in the history
  • Loading branch information
Caneco committed Jan 25, 2019
1 parent 02e1001 commit 98a804a
Show file tree
Hide file tree
Showing 15 changed files with 762 additions and 3 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Caneco
Copyright (c) 2019 Vitor Caneco

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
234 changes: 232 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,232 @@
# artisan-aliases
Save keystrokes and run Artisan commands your way
<p align="center"><img src="https://raw.githubusercontent.com/caneco/artisan-aliases/master/art/logo.png" width="400"/></p>

<p align="center"><img src="https://raw.githubusercontent.com/caneco/artisan-aliases/master/art/preview.png"/></p>

<p align="center">
<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>
<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>
<a href="https://packagist.org/packages/caneco/artisan-aliases"><img src="https://poser.pugx.org/caneco/artisan-aliases/license.svg" alt="License"></a>
</p>

---

# Laravel Artisan Aliases

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..



## Installation

You can install the package via composer:

```
>_ composer require caneco/artisan-aliases
```

#### Registering the service provider
In Laravel 5.5 the service provider will automatically get registered. But if needed just add the service provider in `config/app.php` file:

```
'providers' => [
// ...
Caneco\ArtisanAliases\ArtisanAliasesServiceProvider::class,
];
```

#### Publishing the package assets
To publish the configuration file and `.laravel_alias`, execute the following command and pick this Service Provider:

```
>_ php artisan vendor:publish
Which provider or tag's files would you like to publish?:
[0 ] Publish files from all providers and tags listed below
[1 ] Provider: Caneco\ArtisanAliasesExample:
[… ] ...
```

Or do it in a single command:

```
>_ php artisan vendor:publish --provider="Caneco\ArtisanAliases\ArtisanAliasesServiceProvider"
```

When published, this is the contents of the config file:

```PHP
return [

/*
|--------------------------------------------------------------------------
| Artisan Alias Master Switch
|--------------------------------------------------------------------------
| This option may be used to enable/disable all Artisan alias
| defined in your local or global `.laravel_alias` file
*/
'enabled' => env('ARTISAN_ALIAS_ENABLED', true),

/*
|--------------------------------------------------------------------------
| Default Alias File
|--------------------------------------------------------------------------
| This option allows you to have three ways of load the list of alias. The
| `global` option will only load the alias defined in your home directory,
| while the `local` option, will limit the alias from the list in your
| application. Finally, The `both` option, or anything else, will
| load the alias from both locations.
|
| Supported: "global", "local", "both",
*/
'use_only' => 'both',

];
```




## Usage

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:

```
laravel="inspire"
# cc="clear-compiled"
```

#### Listing existing alias
To list the current alias available you can run the following command:

```
>_ php artisan alias --list
Laravel `Artisan Aliases` 1.0.0
Usage:
alias [-g|--global] [--] [<as>]
Available alias:
laravel inspire
cc clear-compiled
```

Also, the available alias in appear on your artisan command list:

```
$ php artisan list
...
Available commands:
alias Create an alias of another command
cc * Alias for the `clear-compiled` command
clear-compiled Remove the compiled class file
down Put the application into maintenance mode
...
inspire Display an inspiring quote
laravel * Alias for the `inspire` command
list Lists commands
...
```


#### Adding new alias
Add your alias directly in the file `.laravel_alias`, or just use the artisan command:

```
>_ php artisan alias laravel "inspire"
```

And, if you pass the `--global` option the alias will be registered instead in the `.laravel_alias` of your home directory.

```
>_ php artisan alias cc="clear-compiled" --global
```

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.

#### Comments
Anything after the character `#` it's considered a comment and will be not considered for execution.

```
# https://twitter.com/davidhemphill/status/1083466919964041217
migrate:make="make:migration" # DOPE
```

#### Quote surrounding
Surrounding the command with quotes are not mandatory, but if the command to be aliased has some spaces you must use them.

#### Multiple commands
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.

```
# EXAMPLE
tables-up=notifications:table && queue:table && queue:failed-table && ...
```

#### Shell commands
If you prefix your alias with an exclamation point, will be treated as a shell command.

#### Alias*ception…*
Yes, you can also create alias of alias...

#### Artisan groups
If you set your alias with a namespace like `boot:tables` or `boot:cache`, Artisan list will group your alias toghether.

```
# EXAMPLE
boot
boot:cache * Alias for the `config:cache || route:cache || view:cache command`
boot:tables * Alias for the `cache:table || notifications:table || queue:failed-table || queue:table || session:table command`
```




## Gotchas ⚠️

- 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.
- Adding an alias with the same name as other it will result with an exception.
- Having two alias manually defined in the `.laravel_aliases` the last alias command will prevail.
- An alias with the same name as an Artisan command, the Artisan prevail.




## Supported versions

Look at the table below to find out what versions of Laravel are supported on what version of this package:

Laravel Framework | Artisan Alias
:--- | :---
`5.7.*` | `^1.0`




## Road map

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.

Here's the plan for what's coming:

- [ ] Remove an existing alias using the option `--d|delete`
- [ ] Allow to replace an existing alias using the option `--force`
- [ ] Firing a `@handle` method if
- [ ] Alert the user try to add an alias with `sudo` in the command **(usefull?)**
- [ ] Add comments
- [ ] Add tests




## Contributing

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.




## License

The MIT License (MIT). Please see [License File](/caneco/artisan-alias/blob/master/LICENSE.md) for more information.
51 changes: 51 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "caneco/artisan-aliases",
"description": "Save keystrokes and run Artisan commands your way",
"keywords": [
"laravel",
"artisan",
"cli",
"alias",
"aliases"
],
"license": "MIT",
"authors": [
{
"name": "Caneco",
"email": "vitor.caneco@gmail.com"
}
],
"require": {
"php": "^7.1",
"sixlive/dotenv-editor": "^1.1"
},
"require-dev": {
"larapack/dd": "^1.0",
"orchestra/testbench": "^3.7",
"sempro/phpunit-pretty-print": "^1.0",
"phpunit/phpunit": "^6.0|^7.0"
},
"autoload": {
"psr-4": {
"Caneco\\ArtisanAliases\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Caneco\\ArtisanAliases\\Tests\\": "tests/"
}
},
"scripts": {
"test": "phpunit"
},
"config": {
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"Caneco\\ArtisanAliases\\ArtisanAliasesServiceProvider"
]
}
}
}
28 changes: 28 additions & 0 deletions config/aliases.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Artisan Alias Master Switch
|--------------------------------------------------------------------------
| This option may be used to enable/disable all Artisan alias
| defined in your local or global `.laravel_alias` file
*/
'enabled' => env('ARTISAN_ALIAS_ENABLED', true),

/*
|--------------------------------------------------------------------------
| Default Alias File
|--------------------------------------------------------------------------
| This option allows you to have three ways of load the list of alias. The
| `global` option will only load the alias defined in your home directory,
| while the `local` option, will limit the alias from the list in your
| application. Finally, The `both` option, or anything else, will
| load the alias from both locations.
|
| Supported: "global", "local", "both",
*/
'use_only' => 'both',

];
23 changes: 23 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
printerClass="Sempro\PHPUnitPrettyPrinter\PrettyPrinter">
<testsuites>
<testsuite name="ArtisanAliases Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>
46 changes: 46 additions & 0 deletions src/Alias.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Caneco\ArtisanAliases;

use Caneco\ArtisanAliases\AliasFile;
use Caneco\ArtisanAliases\AliasManager;

class Alias
{
public const VERSION = '1.0.0';

public static function store(string $name, string $line, bool $global)
{
$manager = new AliasManager(
$global ? AliasFile::global() : AliasFile::local()
);

return $manager->save(new AliasModel($name, $line));
}

public static function load(?string $location = null): array
{
switch ($location) {
case 'local':
return self::local();
case 'global':
return self::global();
default:
return array_merge(self::global(), self::local());
}
}

public static function local(): array
{
return (new AliasManager(
AliasFile::local()
))->load();
}

public static function global(): array
{
return (new AliasManager(
AliasFile::global()
))->load();
}
}
Loading

0 comments on commit 98a804a

Please sign in to comment.