mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-22 22:59:35 +02:00
tools: highest-endpoint-version -> endpoint-hci-version
This commit is contained in:
parent
2edcd49e99
commit
947c5d364a
3 changed files with 51 additions and 85 deletions
49
tools/endpoint-hci-version/cli.js
Executable file
49
tools/endpoint-hci-version/cli.js
Executable file
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/env node
|
||||
'use strict'
|
||||
|
||||
const mri = require('mri')
|
||||
|
||||
const argv = mri(process.argv.slice(2), {
|
||||
boolean: [
|
||||
'help', 'h',
|
||||
'silent', 's',
|
||||
]
|
||||
})
|
||||
|
||||
if (argv.help || argv.h) {
|
||||
process.stdout.write(`
|
||||
Usage:
|
||||
endpoint-hci-version <profile>
|
||||
Options:
|
||||
--silent -s Output just the version instead of a pretty
|
||||
represenation.
|
||||
Examples:
|
||||
endpoint-hci-version oebb
|
||||
\n`)
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
const {join} = require('path')
|
||||
const createClient = require('../..')
|
||||
|
||||
const profile = require(join(__dirname, '..', '..', 'p', argv._[0]))
|
||||
const client = createClient(
|
||||
profile,
|
||||
'hafas-client-endpoint-hci-version',
|
||||
)
|
||||
|
||||
const silent = argv.silent || argv.s
|
||||
|
||||
;(async () => {
|
||||
const {hciVersion: v} = await client.serverInfo()
|
||||
|
||||
if ('string' !== typeof v || !v) {
|
||||
throw new Error('invalid/unexpected server response')
|
||||
}
|
||||
if (silent) console.log(v)
|
||||
else console.log(v + ' reported as the endpoint version ✔︎')
|
||||
})()
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
})
|
|
@ -1,9 +1,9 @@
|
|||
{
|
||||
"private": true,
|
||||
"name": "find-highest-endpoint-version",
|
||||
"name": "endpoint-hci-version",
|
||||
"version": "1.0.0",
|
||||
"bin": {
|
||||
"hafas-client-find-highest-endpoint-version": "./cli.js"
|
||||
"hafas-client-endpoint-hci-version": "./cli.js"
|
||||
},
|
||||
"author": "Jannis R <mail@jannisr.de>",
|
||||
"license": "ISC",
|
|
@ -1,83 +0,0 @@
|
|||
#!/usr/bin/env node
|
||||
'use strict'
|
||||
|
||||
const mri = require('mri')
|
||||
|
||||
const argv = mri(process.argv.slice(2), {
|
||||
boolean: [
|
||||
'help', 'h',
|
||||
'silent', 's',
|
||||
]
|
||||
})
|
||||
|
||||
if (argv.help || argv.h) {
|
||||
process.stdout.write(`
|
||||
Usage:
|
||||
highest-endpoint-version <profile>
|
||||
Options:
|
||||
--silent -s Output just the version instead of a pretty
|
||||
represenation.
|
||||
Examples:
|
||||
highest-endpoint-version oebb
|
||||
\n`)
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
const {join} = require('path')
|
||||
const createClient = require('../..')
|
||||
|
||||
const profile = require(join(__dirname, '..', '..', 'p', argv._[0]))
|
||||
const id = (ctx, val) => val
|
||||
const origTransformReqBody = profile.transformReqBody || id
|
||||
|
||||
const checkWithVersion = async (version) => {
|
||||
const transformReqBody = (ctx, body) => {
|
||||
body = origTransformReqBody(ctx, body)
|
||||
return {...body, ver: version}
|
||||
}
|
||||
const client = createClient({
|
||||
...profile, transformReqBody
|
||||
}, 'hafas-client-highest-endpoint-version')
|
||||
|
||||
try {
|
||||
await client.locations('foo', {results: 1})
|
||||
} catch (err) {
|
||||
if (err && err.code === 'VERSION') return false
|
||||
const wrapped = new Error(`check for ${version} support failed with an unknown error`)
|
||||
wrapped.originalError = err
|
||||
throw wrapped
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
const silent = argv.silent || argv.s
|
||||
|
||||
;(async () => {
|
||||
const parseVer = ver => parseInt(ver.split('.')[1])
|
||||
let baseMinor = 16
|
||||
if ('string' === typeof profile.ver && profile.ver) {
|
||||
baseMinor = parseVer(profile.ver)
|
||||
} else {
|
||||
const ctx = {opt: {}}
|
||||
const body = profile.transformReqBody(ctx, {})
|
||||
if ('string' === typeof body.ver && body.ver) {
|
||||
baseMinor = parseVer(body.ver)
|
||||
}
|
||||
}
|
||||
|
||||
for (let minor = baseMinor; minor <= 70; minor++) {
|
||||
const v = '1.' + minor
|
||||
if (await checkWithVersion(v)) {
|
||||
if (!silent) console.log(v + ' is supported ✔︎')
|
||||
} else {
|
||||
if (silent) console.log(v)
|
||||
else console.log(v + ' is not supported ✘')
|
||||
process.exit(0)
|
||||
}
|
||||
}
|
||||
process.exit(1)
|
||||
})()
|
||||
.catch((err) => {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
})
|
Loading…
Add table
Reference in a new issue