1 | "use strict";
|
2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7 | };
|
8 | var __metadata = (this && this.__metadata) || function (k, v) {
|
9 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
10 | };
|
11 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
12 | return new (P || (P = Promise))(function (resolve, reject) {
|
13 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
14 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
15 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
16 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
17 | });
|
18 | };
|
19 | Object.defineProperty(exports, "__esModule", { value: true });
|
20 | const _ = require("lodash");
|
21 | const Log_1 = require("../libs/logging/Log");
|
22 | const typedi_1 = require("typedi");
|
23 | const Cache_1 = require("../libs/cache/Cache");
|
24 | const System_1 = require("../libs/system/System");
|
25 | class CacheCommand {
|
26 | constructor() {
|
27 | this.command = 'cache [command] [bin]';
|
28 | this.aliases = 'cache';
|
29 | this.describe = 'Clear cache bins';
|
30 | }
|
31 | builder(yargs) {
|
32 | return yargs;
|
33 | }
|
34 | beforeStartup() {
|
35 | System_1.System.enableDistribution(false);
|
36 | }
|
37 | beforeStorage() {
|
38 | Log_1.Log.options({ enable: false, loggers: [{ name: '*', enable: false }] }, false);
|
39 | }
|
40 | handler(argv) {
|
41 | return __awaiter(this, void 0, void 0, function* () {
|
42 | if (argv.command === 'clear') {
|
43 | const bins = this.cache.getBins();
|
44 | if (argv.bin) {
|
45 | if (bins[argv.bin]) {
|
46 | console.log('clear bin ' + argv.bin);
|
47 | yield bins[argv.bin].store.clearBin(argv.bin);
|
48 | }
|
49 | else {
|
50 | console.log('cache bin with name ' + argv.bin + ' not found.');
|
51 | }
|
52 | }
|
53 | else {
|
54 | for (const k of _.keys(bins)) {
|
55 | console.log('clear bin ' + k);
|
56 | yield bins[k].store.clearBin(k);
|
57 | }
|
58 | }
|
59 | }
|
60 | else if (argv.command === 'bins') {
|
61 | const bins = this.cache.getBins();
|
62 | console.log('Active bins:');
|
63 | for (const k of _.keys(bins)) {
|
64 | console.log('\t- ' + k);
|
65 | yield bins[k].store.clearBin(k);
|
66 | }
|
67 | }
|
68 | else {
|
69 | console.log('no sub command found. Example: cache clear or cache clear someBin');
|
70 | }
|
71 | });
|
72 | }
|
73 | }
|
74 | __decorate([
|
75 | typedi_1.Inject(Cache_1.Cache.NAME),
|
76 | __metadata("design:type", Cache_1.Cache)
|
77 | ], CacheCommand.prototype, "cache", void 0);
|
78 | exports.CacheCommand = CacheCommand;
|
79 |
|
80 |
|