Skip to content

Commit

Permalink
feat(cli): inline output (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo4815162342 committed Aug 24, 2022
1 parent 2d2db3c commit 941d10c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -72,6 +72,7 @@ Options:
-chpath, --cache-path <value> Folder path for cache data (default: "./.dukascopy-cache")
-r, --retries <value> Number of retries for a failed artifact download (default: 0)
-rp, --retry-pause <value> Pause between retries in milliseconds (default: 500)
-in, --inline Makes files smaller in size by removing new lines in the output (works only with json and array formats) (default: false)
-h, --help display help for command
```
</details>
Expand Down
14 changes: 11 additions & 3 deletions src/cli/config.ts
Expand Up @@ -31,7 +31,12 @@ program
.option('-ch, --cache', 'Use cache', false)
.option('-chpath, --cache-path <value>', 'Folder path for cache data', './.dukascopy-cache')
.option('-r, --retries <value>', 'Number of retries for a failed artifact download', Number, 0)
.option('-rp, --retry-pause <value>', 'Pause between retries in milliseconds', Number, 500);
.option('-rp, --retry-pause <value>', 'Pause between retries in milliseconds', Number, 500)
.option(
'-in, --inline',
'Makes files smaller in size by removing new lines in the output (works only with json and array formats)',
false
);

program.parse(process.argv);

Expand All @@ -47,6 +52,7 @@ export interface CliConfig extends Config {
dir: string;
silent: boolean;
debug: boolean;
inline: boolean;
}

const cliConfig: CliConfig = {
Expand All @@ -69,15 +75,17 @@ const cliConfig: CliConfig = {
cacheFolderPath: options.cachePath,
retryCount: options.retries,
pauseBetweenRetriesMs: options.retryPause,
debug: options.debug
debug: options.debug,
inline: options.inline
};

const cliSchema: InputSchema<CliConfig> = {
...schema,
...{
dir: { type: 'string', required: true } as RuleString,
silent: { type: 'boolean', required: false } as RuleBoolean,
debug: { type: 'boolean', required: false } as RuleBoolean
debug: { type: 'boolean', required: false } as RuleBoolean,
inline: { type: 'boolean', required: false } as RuleBoolean
}
};

Expand Down
6 changes: 4 additions & 2 deletions src/cli/index.ts
Expand Up @@ -38,7 +38,8 @@ let {
cacheFolderPath,
dir,
silent,
debug: isDebugActive
debug: isDebugActive,
inline
} = input;

if (isDebugActive) {
Expand Down Expand Up @@ -137,7 +138,8 @@ if (isDebugActive) {

const formatted = formatOutput({ processedData: filteredData, timeframe, format });

savePayload = format === 'csv' ? formatted : JSON.stringify(formatted, null, 2);
savePayload =
format === 'csv' ? formatted : JSON.stringify(formatted, null, inline ? undefined : 2);
} else {
savePayload = format === 'csv' ? '' : JSON.stringify([]);
}
Expand Down

0 comments on commit 941d10c

Please sign in to comment.