Skip to content
This repository was archived by the owner on Apr 16, 2024. It is now read-only.

Commit b9e0402

Browse files
committed
describe:feature - lists the feature's jobs in sequential order
lucid describe:feature [feature]
1 parent efa0eb4 commit b9e0402

File tree

7 files changed

+486
-2
lines changed

7 files changed

+486
-2
lines changed

TODO.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- [ ] Listing
1212
- [x] Services
1313
- [x] Features (per service, and across all services)
14-
- [ ] Jobs per feature
14+
- [x] Jobs per feature
1515
- [ ] Domains
16+
- [ ] Jobs per domain
1617
- [ ] Pretty Interface
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the lucid-console project.
5+
*
6+
* (c) Vinelab <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Lucid\Console\Commands;
13+
14+
use Lucid\Console\Finder;
15+
use Lucid\Console\Parser;
16+
use Illuminate\Console\Command;
17+
use Symfony\Component\Console\Input\InputArgument;
18+
19+
/**
20+
* @author Abed Halawi <[email protected]>
21+
*/
22+
class FeatureDescribeCommand extends Command
23+
{
24+
25+
use Finder;
26+
27+
/**
28+
* The console command name.
29+
*
30+
* @var string
31+
*/
32+
protected $name = 'describe:feature';
33+
34+
/**
35+
* The console command description.
36+
*
37+
* @var string
38+
*/
39+
protected $description = 'List the jobs of the specified feature in sequential order.';
40+
41+
/**
42+
* Execute the console command.
43+
*
44+
* @return bool|null
45+
*/
46+
public function fire()
47+
{
48+
$feature = $this->findFeature('Create Article');
49+
$parser = new Parser();
50+
$jobs = $parser->parseFeatureJobs($feature);
51+
52+
$features = [];
53+
foreach ($jobs as $index => $job) {
54+
$features[$feature->title][] = [$index+1, $job->title, $job->domain->name, $job->relativePath];
55+
}
56+
57+
foreach ($features as $feature => $jobs) {
58+
$this->comment("\n$feature\n");
59+
$this->table(['', 'Job', 'Domain', 'Path'], $jobs);
60+
}
61+
}
62+
63+
64+
/**
65+
* Get the console command arguments.
66+
*
67+
* @return array
68+
*/
69+
protected function getArguments()
70+
{
71+
return [
72+
['feature', InputArgument::REQUIRED, 'The feature name to list the jobs of.'],
73+
];
74+
}
75+
}

src/Components/Domain.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the lucid-console project.
5+
*
6+
* (c) Vinelab <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Lucid\Console\Components;
13+
14+
/**
15+
* @author Abed Halawi <[email protected]>
16+
*/
17+
class Domain extends Component
18+
{
19+
public function __construct($name, $namespace, $path, $relativePath)
20+
{
21+
$this->setAttributes([
22+
'name' => $name,
23+
'namespace' => $namespace,
24+
'realPath' => $path,
25+
'relativePath' => $relativePath,
26+
]);
27+
}
28+
}

src/Components/Job.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the lucid-console project.
5+
*
6+
* (c) Vinelab <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Lucid\Console\Components;
13+
14+
/**
15+
* @author Abed Halawi <[email protected]>
16+
*/
17+
class Job extends Component
18+
{
19+
public function __construct($title, $namespace, $file, $path, $relativePath, Domain $domain)
20+
{
21+
$this->setAttributes([
22+
'title' => $title,
23+
'namespace' => $namespace,
24+
'file' => $file,
25+
'realPath' => $path,
26+
'relativePath' => $relativePath,
27+
'domain' => $domain,
28+
]);
29+
}
30+
31+
public function toArray()
32+
{
33+
$attributes = parent::toArray();
34+
35+
$attributes['domain'] = $attributes['domain']->toArray();
36+
37+
return $attributes;
38+
}
39+
}

src/Finder.php

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,57 @@ public function listServices()
233233
return $services;
234234
}
235235

236+
/**
237+
* Find the service for the given service name.
238+
*
239+
* @param string $service
240+
*
241+
* @return \Lucid\Console\Components\Service
242+
*/
243+
public function findService($service)
244+
{
245+
$finder = new SymfonyFinder();
246+
$dirs = $finder->name($service)->in($this->findServicesRootPath())->directories();
247+
if ($dirs->count() < 1) {
248+
throw new Exception('Service "'.$service.'" could not be found.');
249+
}
250+
251+
foreach ($dirs as $dir) {
252+
$path = $dir->getRealPath();
253+
254+
return new Service(Str::service($service), $path, $this->relativeFromReal($path));
255+
}
256+
}
257+
258+
/**
259+
* Find the feature for the given feature name.
260+
*
261+
* @param string $name
262+
*
263+
* @return \Lucid\Console\Components\Feature
264+
*/
265+
public function findFeature($name)
266+
{
267+
$name = Str::feature($name);
268+
$fileName = "$name.php";
269+
270+
$finder = new SymfonyFinder();
271+
$files = $finder->name($fileName)->in($this->findServicesRootPath())->files();
272+
foreach ($files as $file) {
273+
$path = $file->getRealPath();
274+
$serviceName = strstr($file->getRelativePath(), '/', true);
275+
$service = $this->findService($serviceName);
276+
277+
return new Feature(
278+
Str::realName($name, '/Feature/'),
279+
$fileName,
280+
$path,
281+
$this->relativeFromReal($path),
282+
$service
283+
);
284+
}
285+
}
286+
236287
/**
237288
* Get the list of features,
238289
* optionally withing a specified service.
@@ -256,7 +307,6 @@ public function listFeatures($serviceName = '')
256307
}
257308
}
258309

259-
260310
$features = [];
261311
foreach ($services as $service) {
262312
$serviceFeatures = new Collection();

src/Kernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ class Kernel extends ConsoleKernel
3131
Commands\ServicesListCommand::class,
3232
Commands\FeaturesListCommand::class,
3333
Commands\ControllerMakeCommand::class,
34+
Commands\FeatureDescribeCommand::class,
3435
];
3536
}

0 commit comments

Comments
 (0)