Skip to content

Commit 068d1bc

Browse files
committed
update
1 parent f7a7d22 commit 068d1bc

28 files changed

+3630
-3731
lines changed

delete.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
rm -rf ~/.lc
1+
rm -rf ~/.lcpr
22
rm -rf ~/.vscode-server/extensions/ccagml*

resources/data.json

Lines changed: 2809 additions & 2765 deletions
Large diffs are not rendered by default.

src/childProcessCall/cache.ts

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

src/childProcessCall/cli.ts

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import { myPluginBase } from "./my_plugin_base";
1414
import { config } from "./config";
1515
import { log } from "./log";
16-
import { file } from "./file";
16+
import { storageUtils } from "./storageUtils";
1717
class NewCli {
1818
constructor() {
1919
this.run();
@@ -23,37 +23,19 @@ class NewCli {
2323
if (e.code === 'EPIPE') process.exit();
2424
});
2525
config.init();
26-
this.initLogLevel();
27-
this.initDir();
28-
this.initPlugins((e) => {
29-
if (e) return log.fatal(e);
30-
require('./cache').cache.init();
31-
this.runCommand_new();
32-
return;
33-
});
34-
};
35-
private initLogLevel() {
3626
log.init();
37-
}
38-
39-
private initDir() {
40-
file.init();
41-
file.mkdir(file.homeDir());
42-
}
43-
44-
private initPlugins(cb) {
27+
storageUtils.init();
4528
if (myPluginBase.base_init()) {
4629
myPluginBase.save();
47-
return cb();
30+
storageUtils.initCache();
31+
this.runCommand_new();
4832
}
49-
}
50-
33+
};
5134
private runCommand_new() {
5235
let com_str = process.argv[2];
5336
let auto_js = require("./commands/" + com_str)[com_str + "Command"];
5437
auto_js.handler(auto_js.process_argv(process.argv));
5538
}
5639
}
5740

58-
5941
export const newCli: NewCli = new NewCli();

src/childProcessCall/commands/cache.ts

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
*/
99

1010

11-
let underscore = require('underscore');
11+
// let underscore = require('underscore');
1212

1313

1414
import { helper } from "../helper";
15-
import { log } from "../log";
16-
import { cache } from "../cache";
15+
// import { log } from "../log";
16+
import { storageUtils } from "../storageUtils";
1717
import { session } from "../session";
1818

1919
class CacheCommand {
@@ -26,12 +26,7 @@ class CacheCommand {
2626
type: 'boolean',
2727
describe: 'Delete cache by keyword',
2828
default: false
29-
})
30-
.positional('keyword', {
31-
type: 'string',
32-
describe: 'Cache name or question id',
33-
default: ''
34-
});
29+
});
3530
argv_config.process_argv(argv);
3631

3732
return argv_config.get_result();
@@ -44,33 +39,18 @@ class CacheCommand {
4439
const name = argv.keyword;
4540
const isInteger = Number.isInteger(Number(name));
4641

47-
const caches = cache.list()
42+
const all_data_file = storageUtils.listCache()
4843
.filter(function (f) {
4944
return (name.length === 0) ||
5045
(isInteger ? f.name.startsWith(name + '.') : f.name === name);
5146
});
5247

5348
if (argv.delete) {
54-
for (let f of caches) cache.del(f.name);
55-
} else {
56-
log.info(' %s %63s %s', 'Cache', 'Size', 'Created');
57-
log.info('-'.repeat(86));
58-
59-
underscore.sortBy(caches, function (f) {
60-
let x = parseInt(f.name.split('.')[0], 10);
61-
if (Number.isNaN(x)) x = 0;
62-
return x;
63-
})
64-
.forEach(function (f) {
65-
log.info(' %-60s %8s %s ago',
66-
f.name,
67-
helper.prettySize(f.size),
68-
helper.prettyTime((Date.now() - f.mtime) / 1000));
69-
});
49+
for (let f of all_data_file) {
50+
storageUtils.delCache(f.name);
51+
}
7052
}
7153
};
7254
}
7355

74-
75-
7656
export const cacheCommand: CacheCommand = new CacheCommand();

src/childProcessCall/commands/config.ts

Lines changed: 81 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -8,96 +8,95 @@
88
*/
99

1010

11-
let underscore = require('underscore');
12-
let nconf = require('nconf');
11+
// let underscore = require('underscore');
12+
// let nconf = require('nconf');
1313

1414

15-
import { config } from "../config";
16-
import { log } from "../log";
17-
import { file } from "../file";
18-
import { session } from "../session";
19-
import { helper } from "../helper";
15+
// import { config } from "../config";
16+
// import { log } from "../log";
17+
// import { file } from "../file";
18+
// import { session } from "../session";
19+
// import { helper } from "../helper";
2020

2121
class ConfigCommand {
2222
constructor() {
2323

2424
}
2525

26-
27-
process_argv(argv) {
28-
let argv_config = helper.base_argv().option('a', {
29-
alias: 'all',
30-
type: 'boolean',
31-
describe: 'Show all config',
32-
default: false
33-
})
34-
.option('d', {
35-
alias: 'delete',
36-
type: 'boolean',
37-
describe: 'Delete config by key',
38-
default: false
39-
})
40-
.positional('key', {
41-
type: 'string',
42-
describe: 'Config key, delimited by colon',
43-
default: ''
44-
})
45-
.positional('value', {
46-
type: 'string',
47-
describe: 'Config value',
48-
default: ''
49-
});
50-
argv_config.process_argv(argv);
51-
52-
return argv_config.get_result();
53-
}
54-
55-
56-
prettyConfig(cfg) {
57-
return JSON.stringify(cfg, null, 2);
58-
}
59-
60-
loadConfig(showall) {
61-
const cfg = showall ? config.getAll(true) : nconf.get();
62-
return underscore.omit(cfg, 'type');
63-
}
64-
65-
saveConfig() {
66-
file.write(file.configFile(), this.prettyConfig(this.loadConfig(false)));
67-
}
68-
69-
handler(argv) {
70-
session.argv = argv;
71-
nconf.file('local', file.configFile());
72-
73-
// show all
74-
if (argv.key.length === 0)
75-
return log.info(this.prettyConfig(this.loadConfig(argv.all)));
76-
77-
78-
const v = nconf.get(argv.key);
79-
80-
// delete
81-
if (argv.delete) {
82-
if (v === undefined) return log.fatal('Key not found: ' + argv.key);
83-
nconf.clear(argv.key);
84-
return this.saveConfig();
85-
}
86-
87-
// show
88-
if (argv.value.length === 0) {
89-
if (v === undefined) return log.fatal('Key not found: ' + argv.key);
90-
return log.info(this.prettyConfig(v));
91-
}
92-
93-
// set
94-
try {
95-
nconf.set(argv.key, JSON.parse(argv.value));
96-
} catch (e) {
97-
nconf.set(argv.key, JSON.parse('"' + argv.value + '"'));
98-
}
99-
return this.saveConfig();
100-
};
26+
// process_argv(argv) {
27+
// let argv_config = helper.base_argv().option('a', {
28+
// alias: 'all',
29+
// type: 'boolean',
30+
// describe: 'Show all config',
31+
// default: false
32+
// })
33+
// .option('d', {
34+
// alias: 'delete',
35+
// type: 'boolean',
36+
// describe: 'Delete config by key',
37+
// default: false
38+
// })
39+
// .positional('key', {
40+
// type: 'string',
41+
// describe: 'Config key, delimited by colon',
42+
// default: ''
43+
// })
44+
// .positional('value', {
45+
// type: 'string',
46+
// describe: 'Config value',
47+
// default: ''
48+
// });
49+
// argv_config.process_argv(argv);
50+
51+
// return argv_config.get_result();
52+
// }
53+
54+
55+
// prettyConfig(cfg) {
56+
// return JSON.stringify(cfg, null, 2);
57+
// }
58+
59+
// loadConfig(showall) {
60+
// const cfg = showall ? config.getAll(true) : nconf.get();
61+
// return underscore.omit(cfg, 'type');
62+
// }
63+
64+
// saveConfig() {
65+
// storageUtils.write(storageUtils.configFile(), this.prettyConfig(this.loadConfig(false)));
66+
// }
67+
68+
// handler(argv) {
69+
// session.argv = argv;
70+
// nconf.file('local', storageUtils.configFile());
71+
72+
// // show all
73+
// if (argv.key.length === 0)
74+
// return log.info(this.prettyConfig(this.loadConfig(argv.all)));
75+
76+
77+
// const v = nconf.get(argv.key);
78+
79+
// // delete
80+
// if (argv.delete) {
81+
// if (v === undefined) return log.fatal('Key not found: ' + argv.key);
82+
// nconf.clear(argv.key);
83+
// return this.saveConfig();
84+
// }
85+
86+
// // show
87+
// if (argv.value.length === 0) {
88+
// if (v === undefined) return log.fatal('Key not found: ' + argv.key);
89+
// return log.info(this.prettyConfig(v));
90+
// }
91+
92+
// // set
93+
// try {
94+
// nconf.set(argv.key, JSON.parse(argv.value));
95+
// } catch (e) {
96+
// nconf.set(argv.key, JSON.parse('"' + argv.value + '"'));
97+
// }
98+
// return this.saveConfig();
99+
// };
101100
}
102101

103102

src/childProcessCall/commands/list.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,4 @@ class ListCommand {
7070
};
7171
}
7272

73-
74-
75-
7673
export const listCommand: ListCommand = new ListCommand();

0 commit comments

Comments
 (0)