1
0
Fork 0
mirror of https://github.com/muerwre/vk-tg-bot.git synced 2025-04-24 22:46:41 +07:00

added argument parser

This commit is contained in:
Fedor Katurov 2021-04-07 17:56:52 +07:00
parent e3bf4fef86
commit 51fe9160ca
6 changed files with 45 additions and 2 deletions

View file

@ -5,3 +5,9 @@ Copy `config.example.yml` to `config.yml` and set it up.
#### Running #### Running
`yarn && yarn build && node ./dist/index.js` `yarn && yarn build && node ./dist/index.js`
#### Custom arguments
```bash
node ./dist/index.js \
--config ./config-dev.yml
```

View file

@ -16,11 +16,13 @@
"ramda": "^0.27.1", "ramda": "^0.27.1",
"typescript": "^4.2.3", "typescript": "^4.2.3",
"winston": "^3.3.3", "winston": "^3.3.3",
"yargs": "^17.0.0-candidate.10",
"yup": "^0.32.9" "yup": "^0.32.9"
}, },
"devDependencies": { "devDependencies": {
"@types/ramda": "^0.27.39", "@types/ramda": "^0.27.39",
"@types/winston": "^2.4.4", "@types/winston": "^2.4.4",
"@types/yargs": "^16.0.1",
"@types/yup": "^0.29.11", "@types/yup": "^0.29.11",
"copyfiles": "^2.4.1" "copyfiles": "^2.4.1"
} }

View file

@ -5,9 +5,11 @@ import { Config } from './types';
import { mergeRight } from 'ramda'; import { mergeRight } from 'ramda';
import { validateConfig } from './validate'; import { validateConfig } from './validate';
import logger from '../service/logger'; import logger from '../service/logger';
import { getCmdArg } from '../utils/args';
const configPath = getCmdArg('config')
const defaultConfig = yaml.load<Config>(fs.readFileSync(path.join(__dirname, '../config.example.yml'), 'utf8')); const defaultConfig = yaml.load<Config>(fs.readFileSync(path.join(__dirname, '../config.example.yml'), 'utf8'));
const userConfig = yaml.load<Config>(fs.readFileSync(path.join(__dirname, '../config.yml'), 'utf8')); const userConfig = yaml.load<Config>(fs.readFileSync(configPath || path.join(__dirname, '../config.yml'), 'utf8'));
const config = userConfig && mergeRight(defaultConfig, userConfig) || defaultConfig const config = userConfig && mergeRight(defaultConfig, userConfig) || defaultConfig

View file

@ -3,7 +3,6 @@ import { TelegramService } from './service/telegram';
import logger from './service/logger'; import logger from './service/logger';
import { VkService } from './service/vk'; import { VkService } from './service/vk';
try { try {
const config = prepareConfig() const config = prepareConfig()
const telegramService = new TelegramService(config.telegram) const telegramService = new TelegramService(config.telegram)

9
src/utils/args.ts Normal file
View file

@ -0,0 +1,9 @@
import yargs from 'yargs'
const { hideBin } = require('yargs/helpers')
export type CmdArgument = 'config';
export const getCmdArg = (name: CmdArgument) => (
yargs(hideBin(process.argv)).argv[name] as string | undefined
)

View file

@ -42,6 +42,18 @@
dependencies: dependencies:
winston "*" winston "*"
"@types/yargs-parser@*":
version "20.2.0"
resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-20.2.0.tgz#dd3e6699ba3237f0348cd085e4698780204842f9"
integrity sha512-37RSHht+gzzgYeobbG+KWryeAW8J33Nhr69cjTqSYymXVZEN9NbRYWoYlRtDhHKPVT1FyNKwaTPC1NynKZpzRA==
"@types/yargs@^16.0.1":
version "16.0.1"
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-16.0.1.tgz#5fc5d41f69762e00fbecbc8d4bf9dea47d8726f4"
integrity sha512-x4HABGLyzr5hKUzBC9dvjciOTm11WVH1NWonNjGgxapnTHu5SWUqyqn0zQ6Re0yQU0lsQ6ztLCoMAKDGZflyxA==
dependencies:
"@types/yargs-parser" "*"
"@types/yup@^0.29.11": "@types/yup@^0.29.11":
version "0.29.11" version "0.29.11"
resolved "https://registry.yarnpkg.com/@types/yup/-/yup-0.29.11.tgz#d654a112973f5e004bf8438122bd7e56a8e5cd7e" resolved "https://registry.yarnpkg.com/@types/yup/-/yup-0.29.11.tgz#d654a112973f5e004bf8438122bd7e56a8e5cd7e"
@ -644,6 +656,19 @@ yargs@^16.1.0:
y18n "^5.0.5" y18n "^5.0.5"
yargs-parser "^20.2.2" yargs-parser "^20.2.2"
yargs@^17.0.0-candidate.10:
version "17.0.0-candidate.10"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.0.0-candidate.10.tgz#8d764e4a3633cfd156e90b501124c55d033c89a6"
integrity sha512-vyorQzRrmtJySXUAYAa7oCnsWuWeJuFLhaP86iaUUwNpKYPSuWVrgCdv/cAiQOKSrzMUDIvPgMeahrxKBFOliQ==
dependencies:
cliui "^7.0.2"
escalade "^3.1.1"
get-caller-file "^2.0.5"
require-directory "^2.1.1"
string-width "^4.2.0"
y18n "^5.0.5"
yargs-parser "^20.2.2"
yup@^0.32.9: yup@^0.32.9:
version "0.32.9" version "0.32.9"
resolved "https://registry.yarnpkg.com/yup/-/yup-0.32.9.tgz#9367bec6b1b0e39211ecbca598702e106019d872" resolved "https://registry.yarnpkg.com/yup/-/yup-0.32.9.tgz#9367bec6b1b0e39211ecbca598702e106019d872"