Skip to content

Commit

Permalink
feat(cli): allow custom file name (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo4815162342 authored Sep 6, 2023
1 parent 450f32a commit ed20c0d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
13 changes: 7 additions & 6 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export async function run(argv: NodeJS.Process['argv']) {
retryCount,
failAfterRetryCount,
retryOnEmpty,
pauseBetweenRetriesMs
pauseBetweenRetriesMs,
fileName: customFileName
} = input;

if (isDebugActive) {
Expand Down Expand Up @@ -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);

Expand Down
8 changes: 6 additions & 2 deletions src/cli/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface CliConfig extends ConfigBase {
silent: boolean;
debug: boolean;
inline: boolean;
fileName: string;
}

const now = 'now';
Expand Down Expand Up @@ -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 <value>', '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)',
Expand Down Expand Up @@ -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<CliConfig> = {
Expand All @@ -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
}
};

Expand Down
6 changes: 0 additions & 6 deletions src/cli/types.ts

This file was deleted.

0 comments on commit ed20c0d

Please sign in to comment.