Skip to content

Commit

Permalink
feat: add commander
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgfr committed Mar 7, 2022
1 parent 2db34c6 commit eff585b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "binance-historic",
"version": "1.2.1",
"author": "maxgfr",
"license": "MIT",
"main": "./build/index.js",
Expand Down Expand Up @@ -30,7 +31,7 @@
"test": "jest",
"test:watch": "jest --watch",
"clean": "rimraf build",
"build": "tsc -p tsconfig.json",
"build": "rimraf build && tsc -p tsconfig.json",
"build:watch": "tsc -w -p tsconfig.json",
"build:swc": "swc ./src -d build",
"build:swc:watch": "npm run build:swc -- -w",
Expand All @@ -39,6 +40,7 @@
},
"dependencies": {
"axios": "0.26.0",
"commander": "^9.0.0",
"prompts": "2.4.2"
},
"devDependencies": {
Expand Down
20 changes: 19 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import prompts from 'prompts';
import { PromptResult } from './types';
import { getKline } from './klines';
import { formatDate, saveKline } from './utils';
import { Command } from 'commander';

const questions: Array<prompts.PromptObject> = [
{
Expand Down Expand Up @@ -59,7 +60,7 @@ async function promptUser(): Promise<Partial<PromptResult>> {
return { pair, interval, startDate, endDate, fileName };
}

export async function runPrompt() {
async function processUserInformations() {
const { pair, interval, startDate, endDate, fileName } = await promptUser();
if (!pair || !interval || !startDate || !endDate || !fileName) {
console.log('Missing informations 😭');
Expand All @@ -75,3 +76,20 @@ export async function runPrompt() {
);
console.log('Done 🎉');
}

export async function runCommand() {
const program = new Command();

program
.name('binance-historic')
.description('Utility to download historical klines from binance')
.version('1.2.1');

program
.description(
'Download a JSON file which contains historical klines from binance api',
)
.action(() => processUserInformations());

program.parse();
}
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#! /usr/bin/env node
export { Kline } from './types';
export { getKline } from './klines';
import { runPrompt } from './cli';
import { runCommand } from './cli';

runPrompt();
if (require.main === module) {
runCommand();
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "resolveJsonModule": true, /* Enable importing .json files */
"resolveJsonModule": true /* Enable importing .json files */,
// "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */

/* JavaScript Support */
Expand Down
13 changes: 5 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1114,14 +1114,6 @@ balanced-match@^1.0.0:
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==

binance-historic@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/binance-historic/-/binance-historic-1.2.0.tgz#d0c3e1a21f63f092b61b4ed07eab946055bc5879"
integrity sha512-41a4tYE0r/GxDajxXOG7KWO6r5BFr9zqGvX9dU+lGzcJmQWFBAROaIF0RUn08II6OekR0/hzRa+DMSwe8mjNSQ==
dependencies:
axios "0.26.0"
prompts "2.4.2"

binary-extensions@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d"
Expand Down Expand Up @@ -1343,6 +1335,11 @@ commander@^7.1.0:
resolved "https://registry.yarnpkg.com/commander/-/commander-7.2.0.tgz#a36cb57d0b501ce108e4d20559a150a391d97ab7"
integrity sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==

commander@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-9.0.0.tgz#86d58f24ee98126568936bd1d3574e0308a99a40"
integrity sha512-JJfP2saEKbQqvW+FI93OYUB4ByV5cizMpFMiiJI8xDbBvQvSkIk0VvQdn1CZ8mqAO8Loq2h0gYTYtDFUZUeERw==

[email protected]:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
Expand Down

0 comments on commit eff585b

Please sign in to comment.