Skip to content

Commit

Permalink
include exclude patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
visavi committed Jan 12, 2017
1 parent 04a711e commit 47fdfaa
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
33 changes: 33 additions & 0 deletions cleanup
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
#!/usr/bin/env php
<?php
$options = getopt("i:e:h", ['include:', 'exclude:', 'help']);

if (isset($options['include'])) {
$options['i'] = $options['include'];
}

if (isset($options['exclude'])) {
$options['e'] = $options['exclude'];
}

if (isset($options['h']) || isset($options['help'])) {
echo "Cleaning composer vendor directory".PHP_EOL.PHP_EOL;

echo "\e[0;33mUsage:\e[0m".PHP_EOL;
echo " command [options] [arguments]".PHP_EOL.PHP_EOL;

echo "\e[0;33mOptions:\e[0m".PHP_EOL;
echo " \e[0;32m-h, --help \e[0m Display this help message".PHP_EOL;
echo " \e[0;32m-i, --include \e[0m Add patterns for common files, comma separated".PHP_EOL;
echo " \e[0;32m-e, --exclude \e[0m Remove patterns for common files, comma separated".PHP_EOL.PHP_EOL;

echo "\e[0;33mExample:\e[0m".PHP_EOL;
echo " ./vendor/bin/cleanup --include *.lock,*.txt --exclude doc,docs,test".PHP_EOL;
return;
}

// Default patterns for common files
$patterns = [
Expand Down Expand Up @@ -32,6 +57,14 @@ $patterns = [
'composer.json',
];

if (isset($options['i'])) {
$patterns = array_merge($patterns, explode(',', $options['i']));
}

if (isset($options['e'])) {
$patterns = array_diff($patterns, explode(',', $options['e']));
}

function expandTree($dir) {
$directories = [];
$files = array_diff(scandir($dir), ['.', '..']);
Expand Down
14 changes: 13 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Cleanup
[![Latest Unstable Version](https://poser.pugx.org/visavi/cleanup/v/unstable)](https://packagist.org/packages/visavi/cleanup)
[![License](https://poser.pugx.org/visavi/cleanup/license)](https://packagist.org/packages/visavi/cleanup)

###Cleaning vendor directory
###Cleaning composer vendor directory

It cleans up any tests, descriptions, documentation, examples, etc.

Expand Down Expand Up @@ -49,6 +49,18 @@ composer require visavi/cleanup
./vendor/bin/cleanup
```

### Option
include - include new rules pattern

exclude - excludes from the pattern rule

*the list of arguments must be passed by a comma*

### Example
```
./vendor/bin/cleanup --include *.lock,*.txt --exclude doc,docs,test
```

### License

The class is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

0 comments on commit 47fdfaa

Please sign in to comment.