feat: add no-progress

main
spacemeowx2 2022-10-20 22:05:58 +08:00
parent ddd086cd7e
commit f754303a05
1 changed files with 23 additions and 15 deletions

38
s3si.ts
View File

@ -12,14 +12,14 @@ import { FileExporter } from "./exporter/file.ts";
type Opts = { type Opts = {
profilePath: string; profilePath: string;
exporter: string; exporter: string;
progress: boolean; noProgress: boolean;
help?: boolean; help?: boolean;
}; };
const DEFAULT_OPTS: Opts = { const DEFAULT_OPTS: Opts = {
profilePath: "./profile.json", profilePath: "./profile.json",
exporter: "stat.ink", exporter: "stat.ink",
progress: true, noProgress: false,
help: false, help: false,
}; };
@ -79,7 +79,9 @@ class App {
Options: Options:
--profile-path <path>, -p Path to config file (default: ./profile.json) --profile-path <path>, -p Path to config file (default: ./profile.json)
--exporter <exporter>, -e Exporter to use (default: stat.ink), available: stat.ink,file --exporter <exporter>, -e Exporter list to use (default: stat.ink)
Multiple exporters can be separated by commas
(e.g. "stat.ink,file")
--no-progress, -n Disable progress bar --no-progress, -n Disable progress bar
--help Show this help message and exit`, --help Show this help message and exit`,
); );
@ -139,7 +141,7 @@ Options:
async run() { async run() {
await this.readState(); await this.readState();
const bar = this.opts.progress const bar = !this.opts.noProgress
? new MultiProgressBar({ ? new MultiProgressBar({
title: "Export battles", title: "Export battles",
}) })
@ -213,12 +215,12 @@ Options:
}; };
await Promise.all( await Promise.all(
exporters.map((e) => exporters.map((e) =>
this.exportBattleList( this.exportBattleList({
fetcher, fetcher,
e, exporter: e,
battleList, battleList,
(progress) => redraw(e.name, progress), onStep: (progress) => redraw(e.name, progress),
) })
), ),
); );
} catch (e) { } catch (e) {
@ -238,10 +240,17 @@ Options:
* @param onStep Callback function called when a battle is exported * @param onStep Callback function called when a battle is exported
*/ */
async exportBattleList( async exportBattleList(
fetcher: BattleFetcher, {
exporter: BattleExporter<VsHistoryDetail>, fetcher,
battleList: string[], exporter,
onStep?: (progress: Progress) => void, battleList,
onStep
}: {
fetcher: BattleFetcher,
exporter: BattleExporter<VsHistoryDetail>,
battleList: string[],
onStep?: (progress: Progress) => void,
}
) { ) {
const workQueue = battleList; const workQueue = battleList;
let done = 0; let done = 0;
@ -269,13 +278,12 @@ Options:
const parseArgs = (args: string[]) => { const parseArgs = (args: string[]) => {
const parsed = flags.parse(args, { const parsed = flags.parse(args, {
string: ["profilePath", "exporter"], string: ["profilePath", "exporter"],
boolean: ["help", "progress"], boolean: ["help", "noProgress"],
negatable: ["progress"],
alias: { alias: {
"help": "h", "help": "h",
"profilePath": ["p", "profile-path"], "profilePath": ["p", "profile-path"],
"exporter": ["e"], "exporter": ["e"],
"progress": ["n"], "noProgress": ["n", "no-progress"],
}, },
default: { default: {
progress: true, progress: true,