From ed20c0dd021203e26b4a6b496f14e079b0b39bd5 Mon Sep 17 00:00:00 2001 From: Leonid Pyrlia Date: Wed, 6 Sep 2023 20:35:27 +0200 Subject: [PATCH] feat(cli): allow custom file name (#157) --- src/cli/cli.ts | 13 +++++++------ src/cli/config.ts | 8 ++++++-- src/cli/types.ts | 6 ------ 3 files changed, 13 insertions(+), 14 deletions(-) delete mode 100644 src/cli/types.ts diff --git a/src/cli/cli.ts b/src/cli/cli.ts index 9998345..a340335 100644 --- a/src/cli/cli.ts +++ b/src/cli/cli.ts @@ -47,7 +47,8 @@ export async function run(argv: NodeJS.Process['argv']) { retryCount, failAfterRetryCount, retryOnEmpty, - pauseBetweenRetriesMs + pauseBetweenRetriesMs, + fileName: customFileName } = input; if (isDebugActive) { @@ -80,11 +81,11 @@ export async function run(argv: NodeJS.Process['argv']) { utcOffset }); - const fileName = `${instrument}-${timeframe}${ - timeframe === 'tick' ? '' : '-' + priceType - }-${getDateString(startDate)}-${getDateString(endDate)}.${ - format === Format.csv ? Format.csv : Format.json - }`; + const fileName = + customFileName || + `${instrument}-${timeframe}${timeframe === 'tick' ? '' : '-' + priceType}-${getDateString( + startDate + )}-${getDateString(endDate)}.${format === Format.csv ? Format.csv : Format.json}`; const folderPath = resolve(process.cwd(), dir); const filePath = resolve(folderPath, fileName); diff --git a/src/cli/config.ts b/src/cli/config.ts index 4dd4059..4e5d214 100644 --- a/src/cli/config.ts +++ b/src/cli/config.ts @@ -13,6 +13,7 @@ export interface CliConfig extends ConfigBase { silent: boolean; debug: boolean; inline: boolean; + fileName: string; } const now = 'now'; @@ -54,6 +55,7 @@ const commanderSchema = program '-fr, --no-fail-after-retries', 'A flag indicating whether the process should fail after all retries have been exhausted. If `retries` is `0` this parameter will be ignored' ) + .option('-fn, --file-name ', 'Custom file name for the generated file', '') .option( '-in, --inline', 'Makes files smaller in size by removing new lines in the output (works only with json and array formats)', @@ -92,7 +94,8 @@ export function getConfigFromCliArgs(argv: NodeJS.Process['argv']) { retryOnEmpty: options.retryOnEmpty, pauseBetweenRetriesMs: options.retryPause, debug: options.debug, - inline: options.inline + inline: options.inline, + fileName: options.fileName }; const cliSchema: InputSchema = { @@ -101,7 +104,8 @@ export function getConfigFromCliArgs(argv: NodeJS.Process['argv']) { dir: { type: 'string', required: true } as RuleString, silent: { type: 'boolean', required: false } as RuleBoolean, debug: { type: 'boolean', required: false } as RuleBoolean, - inline: { type: 'boolean', required: false } as RuleBoolean + inline: { type: 'boolean', required: false } as RuleBoolean, + fileName: { type: 'string', required: false } as RuleString } }; diff --git a/src/cli/types.ts b/src/cli/types.ts deleted file mode 100644 index 6e36481..0000000 --- a/src/cli/types.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { ConfigBase } from '../config'; - -export interface CliConfig extends Required { - dir: string; - silent: boolean; -}