Skip to content

Commit aeec13d

Browse files
committed
Initial version
1 parent ea88c4e commit aeec13d

File tree

9 files changed

+83
-88
lines changed

9 files changed

+83
-88
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.phpunit.result.cache
33
.composer/
44
vendor/
5+
minicli

Command/Cache/ClearController.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace librarianphp\Cache;
4+
5+
use Minicli\Command\CommandController;
6+
use Minicli\Config;
7+
8+
class ClearController extends CommandController
9+
{
10+
public function handle(): void
11+
{
12+
/** @var Config $config */
13+
$config = $this->getApp()->config;
14+
if (!$config->has('cache_path')) {
15+
$this->getPrinter()->error("Missing cache_path configuration.");
16+
}
17+
18+
$cache_path = $config->cache_path;
19+
20+
foreach (glob($cache_path . "/*.json") as $filename) {
21+
unlink($filename);
22+
}
23+
24+
$this->getPrinter()->success("Cache cleared.");
25+
}
26+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace librarianphp\Cache;
4+
5+
use Minicli\App;
6+
use Minicli\Command\CommandController;
7+
8+
class DefaultController extends CommandController
9+
{
10+
public function handle(): void
11+
{
12+
$this->getPrinter()->info("./librarian cache [subcommand]", true);
13+
$this->getPrinter()->info("Run \"./librarian cache clear\" to clear cached tags and pages.");
14+
$this->getPrinter()->info("Run \"./librarian cache refresh\" to refresh the cache (clear and reload).");
15+
}
16+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace librarianphp\Cache;
4+
5+
use Librarian\Provider\ContentServiceProvider;
6+
use Minicli\Command\CommandController;
7+
use Minicli\Config;
8+
9+
class RefreshController extends CommandController
10+
{
11+
public function handle(): void
12+
{
13+
/** @var ContentServiceProvider $content_provider */
14+
$content_provider = $this->getApp()->content;
15+
16+
/** @var Config $config */
17+
$config = $this->getApp()->config;
18+
if (!$config->has('cache_path')) {
19+
$this->getPrinter()->error("Missing cache_path configuration.");
20+
}
21+
22+
$cache_path = $config->cache_path;
23+
24+
$this->getPrinter()->info("Clearing cache...");
25+
foreach (glob($cache_path . "/*.json") as $filename) {
26+
unlink($filename);
27+
}
28+
29+
$content_provider->fetchTagList();
30+
31+
$this->getPrinter()->success("Cache updated.");
32+
}
33+
}

Command/Help/DefaultController.php

Lines changed: 0 additions & 46 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# command-help
1+
# command-cache
22

3-
Librarian's built-in help command.
3+
Librarian's built-in cache command.
44

55
```shell
6-
./librarian help
6+
./librarian cache
77
```

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"name": "librarianphp/command-help",
2+
"name": "librarianphp/command-cache",
33
"type": "library",
4-
"description": "Librarian's built-in help command",
4+
"description": "Librarian's built-in cache command",
55
"license": "MIT",
6-
"homepage": "https://github.com/librarianphp/command-demo",
6+
"homepage": "https://github.com/librarianphp/command-cache",
77
"keywords": ["cli","command-line", "markdown"],
88
"autoload": {
99
"psr-4": {

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

minicli

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)