Skip to content

Commit

Permalink
Getting up to first release.
Browse files Browse the repository at this point in the history
  • Loading branch information
judgej committed Aug 21, 2019
1 parent 42ba9ae commit e55ac99
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/build/
/vendor/
composer.lock
composer.phar
6 changes: 6 additions & 0 deletions .semver
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
:major: 3
:minor: 5
:patch: 3
:special: ''
:metadata: ''
44 changes: 44 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Contributing

Contributions are **welcome** and will be fully **credited**.

We accept contributions via pull requests via
[Github](https://github.com/cviebrock/eloquent-taggable).

1. Fork the project.
2. Create your bugfix/feature branch and write your (well-commented) code.
3. Create unit tests for your code:
- Run `composer install --dev` in the root directory to install required testing packages.
- Add your test classes/methods to the `/tests/` directory.
- Run `vendor/bin/phpunit` and make sure everything passes (new and old tests).
3. Commit your changes (and your tests) and push to your branch.
4. Create a new pull request against this package's `master` branch.


## Pull Requests

- **Use the [PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md).**
The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).

- **Add tests!** Your pull request won't be accepted if it doesn't have tests.

- **Document any change in behaviour.** Make sure the `README.md` and any other relevant
documentation are kept up-to-date.

- **Consider our release cycle.** We try to follow [SemVer v2.0.0](http://semver.org/).
Randomly breaking public APIs is not an option.

- **Create feature branches.** Don't ask us to pull from your master branch.

- **One pull request per feature.** If you want to do more than one thing, send multiple pull requests.

- **Send coherent history.** - Make sure each individual commit in your pull request is meaningful.
If you had to make multiple intermediate commits while developing, please
[squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages)
before submitting.

- Don't worry about updating `CHANGELOG.md` or `.semver`. The package administrator
will handle updating those when new releases are created.


**Thank you!**
File renamed without changes.
60 changes: 55 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# laravel-storage-ls

List the contents of Laravel file systems.
List the contents of Laravel file systems/disks.

This is handy to view remote files and diagnose disk connection problems.

[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Total Downloads](https://poser.pugx.org/consilience/laravel-storage-ls/downloads?format=flat)](https://packagist.org/packages/consilience/laravel-storage-ls)
[![Latest Stable Version](https://poser.pugx.org/consilience/laravel-storage-ls/v/stable?format=flat)](https://packagist.org/packages/consilience/laravel-storage-ls)
[![Latest Unstable Version](https://poser.pugx.org/consilience/laravel-storage-ls/v/unstable?format=flat)](https://packagist.org/packages/consilience/laravel-storage-ls)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/consilience/laravel-storage-ls/badges/quality-score.png?format=flat)](https://scrutinizer-ci.com/g/consilience/laravel-storage-ls)

# Usage

Expand All @@ -27,18 +35,60 @@ Available disks:

```bash
$ php artisan storage:ls --disk=s3

# or

$ php artisan storage:ls -d s3
```

```bash
$ ./artisan storage:ls --disk=local
14 2019-03-05 14:27:03 .gitignore
$ ./artisan storage:ls -d local -l
- 14 2019-03-05 14:27:03 .gitignore
d 0 2019-08-21 11:19:46 public
```

## List files/directories in given disk, in given directory
## List files/directories in given directory

```bash
$ php artisan storage:ls -d s3 my-folder/sub-folder
```

## List files/directories recusirvely

```bash
$ php artisan storage:ls -d local -R
/:
.gitignore
public

/public:
dirA
dirB
xyzFile

public/dirA:

public/dirB:
foobarFile
```

Similarly, in long format:

```bash
$ php artisan storage:ls --disk=s3 --dir='my-folder/sub-folder'
$ php artisan storage:ls -d local -Rl
/:
- 14 2019-03-05 14:27:03 .gitignore
d 0 2019-08-21 22:16:46 public

/public:
d 0 2019-08-21 22:16:43 dirB
d 0 2019-08-21 22:17:08 dirB
- 6 2019-08-21 21:54:54 xyzFile

public/dirA:

public/dirB:
- 5 2019-08-21 22:17:08 foobarFile
```

# Installation
Expand Down
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
}
],
"minimum-stability": "dev",
"require": {},
"require": {
"illuminate/support": "~5.8"
},
"require-dev": {
"phpunit/phpunit": "^7.0"
},
"autoload": {
"psr-4": {
"Consilience\\Laravel\\Ls\\": "src/"
Expand Down
28 changes: 28 additions & 0 deletions phpunix.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
printerClass="LimeDeck\Testing\Printer"
processIsolation="false"
stopOnFailure="true">
<testsuites>
<testsuite name="Taggable Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/clover.xml"/>
</logging>
</phpunit>
87 changes: 71 additions & 16 deletions src/Console/Commands/ListStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
use DateTimeInterface;
use Throwable;

class ListStorage extends Command
{
const TYPE_DIR = 'dir';
const TYPE_FILE = 'file';

protected $dirIndex = 0;

protected $signature = 'storage:ls
{--disk= : select the filesystem disk}
{--dir= : list a given directory}';
{directory? : list a given directory}
{--d|disk= : select the filesystem disk}
{--l|long : long format}
{--R|recursive : list subdirectories recursively}';

protected $description = 'List the contents of a file storage disk';

Expand Down Expand Up @@ -50,25 +58,52 @@ public function handle()
return;
}

$selectedDir = $this->option('dir', '/');
$selectedDir = $this->argument('directory') ?? '/';
$recursive = $this->option('recursive');
$longFormat = $this->option('long');

$this->listDirectory($selectedDisk, $selectedDir, $recursive, $longFormat);
}

protected function listDirectory(
string $disk,
string $directory,
bool $recursive,
bool $longFormat
) {
$content = Storage::disk($disk)->listContents($directory);

if ($recursive) {
if ($this->dirIndex) {
$this->line('');
}

$this->dirIndex++;

$content = Storage::disk($selectedDisk)->listContents($selectedDir);
$this->line($directory . ':');
}

$subDirs = [];

foreach ($content as $item) {
$basename = $item['basename'] ?? 'unknown';
$pathname = $item['dirname'] . '/' . $basename;
$dirname = $item['dirname'] ?? '/';

$pathname = $dirname . '/' . $basename;

$size = $item['size'] ?? 0;

$type = $item['type'] ?? 'file';
$type = $item['type'] ?? static::TYPE_FILE;

// Some drivers do not supply the file size by default,
// so make another call to get it.

if ($size === 0 && $type === 'file') {
if ($size === 0 && $type === static::TYPE_FILE && $longFormat) {
try {
$size = Storage::disk($selectedDisk)->getSize($pathname);
} catch (\Throwable $e) {
$size = Storage::disk($disk)->getSize($pathname);
} catch (Throwable $e) {
// Some drivers throw exceptions in some circumstances.
// We just catch and ignore.
}
}

Expand All @@ -80,13 +115,33 @@ public function handle()
$datetime = '';
}

$this->info(sprintf(
'%1s %10d %s %s',
$type === 'dir' ? 'd' : '',
$size,
$datetime,
$basename
));
if ($longFormat) {
$this->line(sprintf(
'%1s %10d %s %s',
$type === static::TYPE_DIR ? 'd' : '-',
$size,
$datetime,
$basename
));
} else {
$message = sprintf('%s', $basename);

if ($type === static::TYPE_FILE) {
$this->info($message);
} else {
$this->warn($message);
}
}

if ($type === static::TYPE_DIR) {
$subDirs[] = $pathname;
}
}

if ($subDirs) {
foreach ($subDirs as $subDir) {
$this->listDirectory($disk, $subDir, $recursive, $longFormat);
}
}
}
}

0 comments on commit e55ac99

Please sign in to comment.