lscontests 2.2.3 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -41,6 +41,7 @@ Options:
41
41
  -d, --days, <day> number of days to display, set to 0 to get all
42
42
  contests infomation (default: "3")
43
43
  -l, --list list all supported OJ and it's abbreviation
44
+ -s, --silent do not print log
44
45
  -o, --oj <ojs...> OJs to display (choices: "at", "cf", "lc", "lg", "nc")
45
46
  -r, --raw print raw contest list
46
47
  -L, --language <lang> set output language (choices: "en", "zh-CN", "zh-NE",
@@ -55,7 +56,7 @@ Options:
55
56
  It performs as follows:
56
57
 
57
58
  <!-- block_cli begin -->
58
- (*The following content was automatically generated using [semantic-release](https://github.com/semantic-release/semantic-release) on Thu, 26 May 2022 11:39:17 GMT*)
59
+ (*The following content was automatically generated using [semantic-release](https://github.com/semantic-release/semantic-release) on Mon, 13 Jun 2022 05:05:09 GMT*)
59
60
 
60
61
  <details>
61
62
  <summary> <code>> lsct -L en</code> </summary>
@@ -64,62 +65,20 @@ It performs as follows:
64
65
  There are 1 contests is running on NowCoder
65
66
 
66
67
  OJ: NowCoder
67
- Contest name: 2022 图论班第一章图匹配例题与习题
68
+ Contest name: 牛客竞赛计算几何专题班扫描线
68
69
  Rule: ICPC
69
- Start time: 5/13/2022, 06:00:00
70
- End time: 5/30/2022, 08:00:00
71
- https://ac.nowcoder.com/acm/contest/34649
70
+ Start time: 6/6/2022, 07:00:00
71
+ End time: 6/30/2022, 08:00:00
72
+ https://ac.nowcoder.com/acm/contest/36088
72
73
 
73
- There are 7 contests on NowCoder,AtCoder,LeetCode in the next 3 days
74
+ There are 1 contests on Codeforces in the next 3 days
74
75
 
75
- OJ: NowCoder
76
- Contest name: 牛客练习赛 99
77
- Rule: ICPC
78
- Start time: 5/27/2022, 11:00:00
79
- End time: 5/27/2022, 13:30:00
80
- https://ac.nowcoder.com/acm/contest/34330
81
-
82
- OJ: AtCoder
83
- Contest name: Ⓗ AtCoder Heuristic Contest 011
84
- Rule: AtCoder
85
- Start time: 5/28/2022, 03:00:00
86
- End time: 6/5/2022, 10:00:00
87
- https://atcoder.jp/contests/ahc011
88
-
89
- OJ: NowCoder
90
- Contest name: MINIEYE 杯第十六届华中科技大学程序设计邀请赛
91
- Rule: ICPC
92
- Start time: 5/28/2022, 04:30:00
93
- End time: 5/28/2022, 09:30:00
94
- https://ac.nowcoder.com/acm/contest/34866
95
-
96
- OJ: NowCoder
97
- Contest name: 福建农林大学校赛(同步赛)
76
+ OJ: Codeforces
77
+ Contest name: Codeforces Round #799 (Div. 4)
98
78
  Rule: ICPC
99
- Start time: 5/28/2022, 05:30:00
100
- End time: 5/28/2022, 09:30:00
101
- https://ac.nowcoder.com/acm/contest/33869
102
-
103
- OJ: AtCoder
104
- Contest name: Ⓐ NOMURA Programming Contest 2022(AtCoder Beginner Contest 253)
105
- Rule: AtCoder
106
- Start time: 5/28/2022, 12:00:00
107
- End time: 5/28/2022, 13:40:00
108
- https://atcoder.jp/contests/abc253
109
-
110
- OJ: LeetCode
111
- Contest name: Biweekly Contest 79
112
- Rule: AtCoder
113
- Start time: 5/28/2022, 14:30:00
114
- End time: 5/28/2022, 16:00:00
115
- https://leetcode.com/contest/biweekly-contest-79
116
-
117
- OJ: LeetCode
118
- Contest name: Weekly Contest 295
119
- Rule: AtCoder
120
- Start time: 5/29/2022, 02:30:00
121
- End time: 5/29/2022, 04:00:00
122
- https://leetcode.com/contest/weekly-contest-295
79
+ Start time: 6/14/2022, 14:35:00
80
+ End time: 6/14/2022, 16:50:00
81
+ https://codeforces.com/contests/1692
123
82
  ```
124
83
 
125
84
  </details>
@@ -128,37 +87,51 @@ https://leetcode.com/contest/weekly-contest-295
128
87
  <summary> <code>> lsct -o at cf -d 7 -L en</code> </summary>
129
88
 
130
89
  ```text
131
- No running contests
90
+ There are no running contests on AtCoder,Codeforces
132
91
 
133
- There are 4 contests on AtCoder,Codeforces in the next 7 days
92
+ There are 6 contests on Codeforces,AtCoder in the next 7 days
134
93
 
135
- OJ: AtCoder
136
- Contest name: AtCoder Heuristic Contest 011
137
- Rule: AtCoder
138
- Start time: 5/28/2022, 03:00:00
139
- End time: 6/5/2022, 10:00:00
140
- https://atcoder.jp/contests/ahc011
94
+ OJ: Codeforces
95
+ Contest name: Codeforces Round #799 (Div. 4)
96
+ Rule: ICPC
97
+ Start time: 6/14/2022, 14:35:00
98
+ End time: 6/14/2022, 16:50:00
99
+ https://codeforces.com/contests/1692
141
100
 
142
- OJ: AtCoder
143
- Contest name: NOMURA Programming Contest 2022(AtCoder Beginner Contest 253)
144
- Rule: AtCoder
145
- Start time: 5/28/2022, 12:00:00
146
- End time: 5/28/2022, 13:40:00
147
- https://atcoder.jp/contests/abc253
101
+ OJ: Codeforces
102
+ Contest name: Codeforces Round #800 (Div. 1)
103
+ Rule: Codeforces
104
+ Start time: 6/16/2022, 14:35:00
105
+ End time: 6/16/2022, 16:35:00
106
+ https://codeforces.com/contests/1693
107
+
108
+ OJ: Codeforces
109
+ Contest name: Codeforces Round #800 (Div. 2)
110
+ Rule: Codeforces
111
+ Start time: 6/16/2022, 14:35:00
112
+ End time: 6/16/2022, 16:35:00
113
+ https://codeforces.com/contests/1694
148
114
 
149
115
  OJ: AtCoder
150
- Contest name: Ⓐ AtCoder Regular Contest 141
116
+ Contest name: Ⓐ Tokio Marine & Nichido Fire Insurance Programming Contest 2022(AtCoder Beginner Contest 256)
151
117
  Rule: AtCoder
152
- Start time: 5/29/2022, 12:00:00
153
- End time: 5/29/2022, 14:00:00
154
- https://atcoder.jp/contests/arc141
118
+ Start time: 6/18/2022, 12:00:00
119
+ End time: 6/18/2022, 13:40:00
120
+ https://atcoder.jp/contests/abc256
155
121
 
156
122
  OJ: Codeforces
157
- Contest name: CodeCraft-22 and Codeforces Round #795 (Div. 2)
123
+ Contest name: Codeforces Round #TBA (Div. 2)
158
124
  Rule: Codeforces
159
- Start time: 5/31/2022, 14:35:00
160
- End time: 5/31/2022, 16:35:00
161
- https://codeforces.com/contests/1691
125
+ Start time: 6/18/2022, 14:35:00
126
+ End time: 6/18/2022, 16:35:00
127
+ https://codeforces.com/contests/1695
128
+
129
+ OJ: AtCoder
130
+ Contest name: Ⓐ AtCoder Regular Contest 142
131
+ Rule: AtCoder
132
+ Start time: 6/19/2022, 12:00:00
133
+ End time: 6/19/2022, 14:00:00
134
+ https://atcoder.jp/contests/arc142
162
135
  ```
163
136
 
164
137
  </details>
@@ -172,99 +145,91 @@ https://codeforces.com/contests/1691
172
145
  "upcoming": [
173
146
  {
174
147
  "ojName": "AtCoder",
175
- "name": " AtCoder Heuristic Contest 011",
148
+ "name": " Tokio Marine & Nichido Fire Insurance Programming Contest 2022(AtCoder Beginner Contest 256)",
176
149
  "rule": "AtCoder",
177
- "startTime": "2022-05-28T03:00:00.000Z",
178
- "endTime": "2022-06-05T10:00:00.000Z",
179
- "url": "https://atcoder.jp/contests/ahc011"
150
+ "startTime": "2022-06-18T12:00:00.000Z",
151
+ "endTime": "2022-06-18T13:40:00.000Z",
152
+ "url": "https://atcoder.jp/contests/abc256"
180
153
  },
181
154
  {
182
155
  "ojName": "AtCoder",
183
- "name": "Ⓐ NOMURA Programming Contest 2022(AtCoder Beginner Contest 253)",
156
+ "name": "Ⓐ AtCoder Regular Contest 142",
184
157
  "rule": "AtCoder",
185
- "startTime": "2022-05-28T12:00:00.000Z",
186
- "endTime": "2022-05-28T13:40:00.000Z",
187
- "url": "https://atcoder.jp/contests/abc253"
158
+ "startTime": "2022-06-19T12:00:00.000Z",
159
+ "endTime": "2022-06-19T14:00:00.000Z",
160
+ "url": "https://atcoder.jp/contests/arc142"
188
161
  },
189
162
  {
190
163
  "ojName": "AtCoder",
191
- "name": "Ⓐ AtCoder Regular Contest 141",
164
+ "name": "Ⓐ NS Solutions Corporation Programming Contest 2022(AtCoder Beginner Contest 257)",
192
165
  "rule": "AtCoder",
193
- "startTime": "2022-05-29T12:00:00.000Z",
194
- "endTime": "2022-05-29T14:00:00.000Z",
195
- "url": "https://atcoder.jp/contests/arc141"
166
+ "startTime": "2022-06-25T12:00:00.000Z",
167
+ "endTime": "2022-06-25T13:40:00.000Z",
168
+ "url": "https://atcoder.jp/contests/abc257"
196
169
  },
197
170
  {
198
171
  "ojName": "AtCoder",
199
- "name": "Ⓐ AtCoder Beginner Contest 254",
172
+ "name": "Ⓐ AtCoder Regular Contest 143",
200
173
  "rule": "AtCoder",
201
- "startTime": "2022-06-04T12:00:00.000Z",
202
- "endTime": "2022-06-04T13:40:00.000Z",
203
- "url": "https://atcoder.jp/contests/abc254"
174
+ "startTime": "2022-06-26T12:00:00.000Z",
175
+ "endTime": "2022-06-26T14:00:00.000Z",
176
+ "url": "https://atcoder.jp/contests/arc143"
204
177
  },
205
178
  {
206
179
  "ojName": "AtCoder",
207
- "name": "Ⓐ Aising Programming Contest 2022(AtCoder Beginner Contest 255)",
180
+ "name": "Ⓐ AtCoder Beginner Contest 258",
208
181
  "rule": "AtCoder",
209
- "startTime": "2022-06-11T12:00:00.000Z",
210
- "endTime": "2022-06-11T13:40:00.000Z",
211
- "url": "https://atcoder.jp/contests/abc255"
182
+ "startTime": "2022-07-02T12:00:00.000Z",
183
+ "endTime": "2022-07-02T13:40:00.000Z",
184
+ "url": "https://atcoder.jp/contests/abc258"
212
185
  },
213
186
  {
214
187
  "ojName": "AtCoder",
215
- "name": " AtCoder Regular Contest 142",
188
+ "name": " AtCoder Heuristic Contest 012",
216
189
  "rule": "AtCoder",
217
- "startTime": "2022-06-19T12:00:00.000Z",
218
- "endTime": "2022-06-19T14:00:00.000Z",
219
- "url": "https://atcoder.jp/contests/arc142"
220
- },
221
- {
222
- "ojName": "AtCoder",
223
- "name": "Ⓐ AtCoder Regular Contest 143",
224
- "rule": "AtCoder",
225
- "startTime": "2022-06-26T12:00:00.000Z",
226
- "endTime": "2022-06-26T14:00:00.000Z",
227
- "url": "https://atcoder.jp/contests/arc143"
190
+ "startTime": "2022-07-03T06:00:00.000Z",
191
+ "endTime": "2022-07-03T10:00:00.000Z",
192
+ "url": "https://atcoder.jp/contests/ahc012"
228
193
  },
229
194
  {
230
195
  "ojName": "Codeforces",
231
- "name": "CodeCraft-22 and Codeforces Round #795 (Div. 2)",
232
- "rule": "Codeforces",
233
- "startTime": "2022-05-31T14:35:00.000Z",
234
- "endTime": "2022-05-31T16:35:00.000Z",
235
- "url": "https://codeforces.com/contests/1691"
196
+ "name": "Codeforces Round #799 (Div. 4)",
197
+ "rule": "ICPC",
198
+ "startTime": "2022-06-14T14:35:00.000Z",
199
+ "endTime": "2022-06-14T16:50:00.000Z",
200
+ "url": "https://codeforces.com/contests/1692"
236
201
  },
237
202
  {
238
203
  "ojName": "Codeforces",
239
- "name": "Codeforces Round #796 (Div. 1)",
204
+ "name": "Codeforces Round #800 (Div. 1)",
240
205
  "rule": "Codeforces",
241
- "startTime": "2022-06-03T14:35:00.000Z",
242
- "endTime": "2022-06-03T16:35:00.000Z",
243
- "url": "https://codeforces.com/contests/1687"
206
+ "startTime": "2022-06-16T14:35:00.000Z",
207
+ "endTime": "2022-06-16T16:35:00.000Z",
208
+ "url": "https://codeforces.com/contests/1693"
244
209
  },
245
210
  {
246
211
  "ojName": "Codeforces",
247
- "name": "Codeforces Round #796 (Div. 2)",
212
+ "name": "Codeforces Round #800 (Div. 2)",
248
213
  "rule": "Codeforces",
249
- "startTime": "2022-06-03T14:35:00.000Z",
250
- "endTime": "2022-06-03T16:35:00.000Z",
251
- "url": "https://codeforces.com/contests/1688"
214
+ "startTime": "2022-06-16T14:35:00.000Z",
215
+ "endTime": "2022-06-16T16:35:00.000Z",
216
+ "url": "https://codeforces.com/contests/1694"
252
217
  },
253
218
  {
254
219
  "ojName": "Codeforces",
255
- "name": "Codeforces Round #797 (Div. 3)",
256
- "rule": "ICPC",
257
- "startTime": "2022-06-07T14:35:00.000Z",
258
- "endTime": "2022-06-07T16:50:00.000Z",
259
- "url": "https://codeforces.com/contests/1690"
220
+ "name": "Codeforces Round #TBA (Div. 2)",
221
+ "rule": "Codeforces",
222
+ "startTime": "2022-06-18T14:35:00.000Z",
223
+ "endTime": "2022-06-18T16:35:00.000Z",
224
+ "url": "https://codeforces.com/contests/1695"
260
225
  },
261
226
  {
262
227
  "ojName": "Codeforces",
263
- "name": "Codeforces Round #798 (Div. 2)",
228
+ "name": "Codeforces Global Round 21",
264
229
  "rule": "Codeforces",
265
- "startTime": "2022-06-10T16:35:00.000Z",
266
- "endTime": "2022-06-10T18:35:00.000Z",
267
- "url": "https://codeforces.com/contests/1689"
230
+ "startTime": "2022-06-25T14:35:00.000Z",
231
+ "endTime": "2022-06-25T16:35:00.000Z",
232
+ "url": "https://codeforces.com/contests/1696"
268
233
  }
269
234
  ]
270
235
  }
@@ -275,16 +240,16 @@ https://codeforces.com/contests/1691
275
240
 
276
241
  ### API
277
242
 
278
- For more detailed API documentation, please visit <https://lsct.agoh.xyz>.
243
+ For more detailed API documentation, please visit <https://lsct.stagoh.com>.
279
244
 
280
245
  If you want to get a list of contest information in your project by calling *lscontests*, or if you need to add support for other OJs, then you can call the *lscontests* API as follows:
281
246
 
282
247
  #### Get text for contests information
283
248
 
284
249
  ```typescript
285
- import { getContestInfo } from "lscontests";
250
+ import lsct from "lscontests";
286
251
 
287
- getContestsInfoText({ abbrList: ["cf", "lg"] }).then(console.log);
252
+ new lsct({ abbrList: ["cf", "lg"] }).getContestsText().then(console.log);
288
253
  ```
289
254
 
290
255
  This code gives the same result as `lsct -o cf lg`.
@@ -292,9 +257,9 @@ This code gives the same result as `lsct -o cf lg`.
292
257
  #### Get list for contests information
293
258
 
294
259
  ```typescript
295
- import { getContestList } from "lscontests";
260
+ import lsct from "lscontests";
296
261
 
297
- getContests({ sort: false }).then(console.log);
262
+ new lsct({ abbrList: ["cf", "lg"] }).getContests().then(console.log);
298
263
  ```
299
264
 
300
265
  This code gives the same result as `lsct -r --no-sort`.
@@ -302,7 +267,7 @@ This code gives the same result as `lsct -r --no-sort`.
302
267
  #### Add support for other OJ
303
268
 
304
269
  ```typescript
305
- import { addOJ, getContestsInfoText, getContests } from "lscontests";
270
+ import lsct, { addOJ } from "lscontests";
306
271
 
307
272
  addOJ("ts", {
308
273
  name: "testOJ", get: async () => [{
@@ -316,9 +281,9 @@ addOJ("ts", {
316
281
  });
317
282
 
318
283
  async function main() {
319
- console.log(await getContestsInfoText({ abbrList: ["cf", "ts"], days: 1 }, "en"));
284
+ console.log(await new lsct({ abbrList: ["cf", "ts"], days: 1 }).getContestsText("en"));
320
285
  console.log();
321
- console.log(await getContests({ abbrList: ["at", "ts"], days: 7 }));
286
+ console.log(await new lsct({ abbrList: ["at", "ts"], days: 7 }).getContests());
322
287
  }
323
288
 
324
289
  main();
@@ -327,30 +292,23 @@ main();
327
292
  This code gives the following results:
328
293
 
329
294
  ```text
330
- There are 2 contests is running on Codeforces,testOJ
331
-
332
- OJ: Codeforces
333
- Contest name: Educational Codeforces Round 128 (Rated for Div. 2)
334
- Rule: ICPC
335
- Start time: 2022/5/13 22:35:00
336
- End time: 2022/5/14 00:35:00
337
- https://codeforces.com/contests/1680
295
+ There are 1 contests is running on testOJ
338
296
 
339
297
  OJ: testOJ
340
298
  Contest name: testContest
341
299
  Rule: ICPC
342
- Start time: 2022/5/13 23:23:31
343
- End time: 2022/5/14 00:23:31
300
+ Start time: 2022/6/10 21:43:58
301
+ End time: 2022/6/10 22:43:58
344
302
  https://www.test.com
345
303
 
346
- There are 1 contests on Codeforces,testOJ in the next 1 days
304
+ There are 1 contests on Codeforces in the next 1 days
347
305
 
348
306
  OJ: Codeforces
349
- Contest name: Codeforces Round #791 (Div. 2)
307
+ Contest name: Codeforces Round #798 (Div. 2)
350
308
  Rule: Codeforces
351
- Start time: 2022/5/14 17:35:00
352
- End time: 2022/5/14 19:35:00
353
- https://codeforces.com/contests/1679
309
+ Start time: 2022/6/11 00:35:00
310
+ End time: 2022/6/11 02:35:00
311
+ https://codeforces.com/contests/1689
354
312
 
355
313
  {
356
314
  running: [
@@ -358,27 +316,19 @@ https://codeforces.com/contests/1679
358
316
  ojName: 'testOJ',
359
317
  name: 'testContest',
360
318
  rule: 'ICPC',
361
- startTime: 2022-05-13T15:23:37.245Z,
362
- endTime: 2022-05-13T16:23:37.246Z,
319
+ startTime: 2022-06-10T13:44:01.380Z,
320
+ endTime: 2022-06-10T14:44:01.381Z,
363
321
  url: 'https://www.test.com'
364
322
  }
365
323
  ],
366
324
  upcoming: [
367
325
  {
368
326
  ojName: 'AtCoder',
369
- name: 'Ⓐ Panasonic Programming Contest 2022(AtCoder Beginner Contest 251)',
370
- rule: 'AtCoder',
371
- startTime: 2022-05-14T12:00:00.000Z,
372
- endTime: 2022-05-14T13:40:00.000Z,
373
- url: 'https://atcoder.jp/contests/abc251'
374
- },
375
- {
376
- ojName: 'AtCoder',
377
- name: 'Ⓐ AtCoder Regular Contest 140',
327
+ name: 'Ⓐ Aising Programming Contest 2022AtCoder Beginner Contest 255)',
378
328
  rule: 'AtCoder',
379
- startTime: 2022-05-15T12:00:00.000Z,
380
- endTime: 2022-05-15T14:00:00.000Z,
381
- url: 'https://atcoder.jp/contests/arc140'
329
+ startTime: 2022-06-11T12:00:00.000Z,
330
+ endTime: 2022-06-11T13:40:00.000Z,
331
+ url: 'https://atcoder.jp/contests/abc255'
382
332
  }
383
333
  ]
384
334
  }
@@ -389,7 +339,7 @@ https://codeforces.com/contests/1679
389
339
  ```typescript
390
340
  import { cli } from "lscontests";
391
341
 
392
- cli("-o cf -L en").then(console.log);
342
+ cli("-o cf -L en", undefined, console.log);
393
343
  ```
394
344
 
395
345
  This code gives the same result as `lsct -o cf -L en`.
package/dist/cli.d.ts CHANGED
@@ -1,8 +1,11 @@
1
1
  #!/usr/bin/env node
2
+ import winston from "winston";
2
3
  /**
3
4
  * CLI entrypoint
4
- * @param arg Arguments
5
+ * @param args Arguments
5
6
  * @param name Program name
6
- * @returns CLI output content
7
+ * @param out Output result
8
+ * @param log_level Log level
9
+ * @param log_transport A winston transport instance
7
10
  */
8
- export declare function cli(arg?: string, name?: string): Promise<string>;
11
+ export declare function cli(args?: string, name?: string, out?: (msg: string) => void, log_level?: string, log_transport?: winston.transports.ConsoleTransportInstance): Promise<void>;
package/dist/cli.js CHANGED
@@ -14,73 +14,69 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  };
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.cli = void 0;
17
+ const commander_1 = __importDefault(require("commander"));
18
+ const lodash_1 = __importDefault(require("lodash"));
19
+ const winston_1 = __importDefault(require("winston"));
20
+ const _1 = __importDefault(require("."));
17
21
  const package_json_1 = require("../package.json");
18
- const commander_1 = require("commander");
19
22
  const oj_1 = require("./lib/oj");
20
- const _1 = require(".");
21
23
  const locale_1 = require("./locale");
22
- const lodash_1 = __importDefault(require("lodash"));
23
24
  function initCmd() {
24
- return new commander_1.Command()
25
- .name(Object.keys(package_json_1.bin)[0])
25
+ return new commander_1.default.Command()
26
26
  .version(package_json_1.version)
27
27
  .option("-d, --days, <day>", "number of days to display, set to 0 to get all contests infomation", "3")
28
28
  .option("-l, --list", "list all supported OJ and it's abbreviation")
29
- .addOption(new commander_1.Option("-o, --oj <ojs...>", "OJs to display").choices(Object.keys(oj_1.alloj)))
30
- .addOption(new commander_1.Option("-r, --raw", "print raw contest list").conflicts("language"))
31
- .addOption(new commander_1.Option("-L, --language <lang>", "set output language").default("zh-CN").choices(locale_1.langList))
29
+ .option("-s, --silent", "do not print log")
30
+ .addOption(new commander_1.default.Option("-o, --oj <ojs...>", "OJs to display").choices(Object.keys(oj_1.alloj)))
31
+ .addOption(new commander_1.default.Option("-r, --raw", "print raw contest list").conflicts("language"))
32
+ .addOption(new commander_1.default.Option("-L, --language <lang>", "set output language").default("zh-CN").choices(locale_1.langList))
32
33
  .option("--no-sort", "do not sort by contests start time, but by OJ order")
33
34
  .option("--no-running", "do not list all running contests")
34
35
  .option("--no-upcoming", "do not list all upcoming contests");
35
36
  }
36
37
  /**
37
38
  * CLI entrypoint
38
- * @param arg Arguments
39
+ * @param args Arguments
39
40
  * @param name Program name
40
- * @returns CLI output content
41
+ * @param out Output result
42
+ * @param log_level Log level
43
+ * @param log_transport A winston transport instance
41
44
  */
42
- function cli(arg, name) {
45
+ function cli(args, name, out = console.log, log_level = "info", log_transport = winston_1.default.transports.Console) {
43
46
  return __awaiter(this, void 0, void 0, function* () {
44
- const cmd = initCmd();
45
- if (arg === undefined)
46
- cmd.parse();
47
- else {
48
- let msg = "";
49
- try {
50
- if (name)
51
- cmd.name(name);
52
- cmd
53
- .configureOutput({
54
- writeOut: str => msg = str,
55
- writeErr: str => msg = str,
56
- outputError: str => msg = str
57
- })
58
- .exitOverride()
59
- .parse(arg.split(" "), { from: "user" });
60
- }
61
- catch (e) {
62
- return msg;
63
- }
47
+ const cmd = initCmd()
48
+ .name(name !== null && name !== void 0 ? name : Object.keys(package_json_1.bin)[0])
49
+ .configureOutput({
50
+ writeOut: out,
51
+ writeErr: out
52
+ })
53
+ .exitOverride();
54
+ try {
55
+ cmd.parse(args === null || args === void 0 ? void 0 : args.split(" "), { from: "user" });
56
+ }
57
+ catch (e) {
58
+ return;
64
59
  }
65
60
  const opts = cmd.opts();
66
61
  if (opts.list)
67
- return " abbr OJ\n" + JSON.stringify(lodash_1.default.mapValues(oj_1.alloj, val => val.name), null, 2);
62
+ out(JSON.stringify(lodash_1.default.mapValues(oj_1.alloj, val => val.name), null, 2));
68
63
  else {
69
- const config = {
64
+ const lsct = new _1.default({
70
65
  abbrList: lodash_1.default.uniq(opts.oj),
71
66
  days: parseInt(opts.days),
72
67
  sort: opts.sort,
73
68
  running: opts.running,
74
- upcoming: opts.upcoming
75
- };
69
+ upcoming: opts.upcoming,
70
+ silent: opts.silent
71
+ }, log_level, log_transport);
76
72
  if (opts.raw)
77
- return JSON.stringify(yield (0, _1.getContests)(config), null, 2);
73
+ out(JSON.stringify(yield lsct.getContests(), null, 2));
78
74
  else
79
- return yield (0, _1.getContestsInfoText)(config, opts.language);
75
+ out(yield lsct.getContestsText(opts.language));
80
76
  }
81
77
  });
82
78
  }
83
79
  exports.cli = cli;
84
80
  if (require.main === module)
85
- cli().then(console.log);
81
+ cli();
86
82
  //# sourceMappingURL=cli.js.map
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,kDAA+C;AAC/C,yCAA4C;AAC5C,iCAAiC;AACjC,wBAA6D;AAC7D,qCAAoC;AACpC,oDAAuB;AAEvB,SAAS,OAAO;IAEZ,OAAO,IAAI,mBAAO,EAAE;SACf,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kBAAG,CAAC,CAAC,CAAC,CAAC,CAAC;SACzB,OAAO,CAAC,sBAAO,CAAC;SAChB,MAAM,CAAC,mBAAmB,EAAE,oEAAoE,EAAE,GAAG,CAAC;SACtG,MAAM,CAAC,YAAY,EAAE,6CAA6C,CAAC;SACnE,SAAS,CAAC,IAAI,kBAAM,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,UAAK,CAAC,CAAC,CAAC;SACxF,SAAS,CAAC,IAAI,kBAAM,CAAC,WAAW,EAAE,wBAAwB,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;SAClF,SAAS,CAAC,IAAI,kBAAM,CAAC,uBAAuB,EAAE,qBAAqB,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,iBAAQ,CAAC,CAAC;SACxG,MAAM,CAAC,WAAW,EAAE,qDAAqD,CAAC;SAC1E,MAAM,CAAC,cAAc,EAAE,kCAAkC,CAAC;SAC1D,MAAM,CAAC,eAAe,EAAE,mCAAmC,CAAC,CAAC;AACtE,CAAC;AAED;;;;;GAKG;AACH,SAAsB,GAAG,CAAC,GAAY,EAAE,IAAa;;QAEjD,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;QACtB,IAAG,GAAG,KAAK,SAAS;YAAE,GAAG,CAAC,KAAK,EAAE,CAAC;aAElC;YACI,IAAI,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E,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,IAAI,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;;gBAC/D,GAAG,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;SACvD;IACL,CAAC;CAAA;AAjCD,kBAiCC;AAED,IAAG,OAAO,CAAC,IAAI,KAAK,MAAM;IAAE,GAAG,EAAE,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,27 +1,23 @@
1
- import { contest } from "./lib/contest";
2
- export declare type config = {
1
+ import winston from "winston";
2
+ import { Contest } from "./lib/contest";
3
+ export interface LscontestsConfig {
3
4
  abbrList?: string[];
4
5
  days?: number;
5
6
  sort?: boolean;
6
7
  running?: boolean;
7
8
  upcoming?: boolean;
8
- };
9
- /**
10
- * Get the list of all contests matching the given config
11
- * @param config The config of contests that want to get
12
- * @returns A Promise that contains an array of all contests that match the given config
13
- */
14
- export declare function getContests(config?: config): Promise<{
15
- running: contest[];
16
- upcoming: contest[];
17
- }>;
18
- /**
19
- * Get the detailed text of all contests matching the given config
20
- * @param config The config of contests that want to get
21
- * @param language Language of the output text
22
- * @returns A string containing detail text of contests that match the given config
23
- */
24
- export declare function getContestsInfoText(config?: config, language?: string): Promise<string>;
9
+ silent?: boolean;
10
+ }
11
+ export default class Lscontests {
12
+ private config;
13
+ private logger;
14
+ constructor(config?: LscontestsConfig, log_level?: string, log_transport?: winston.transports.ConsoleTransportInstance);
15
+ getContests(): Promise<{
16
+ running: Contest[];
17
+ upcoming: Contest[];
18
+ }>;
19
+ getContestsText(language?: string): Promise<string>;
20
+ }
25
21
  export * from "./lib/contest";
26
22
  export { cli } from "./cli";
27
- export { oj, addOJ } from "./lib/oj";
23
+ export { OJ, addOJ } from "./lib/oj";