forked from BLOCKvIO/blockv-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
39 lines (27 loc) · 850 Bytes
/
cli.js
File metadata and controls
39 lines (27 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env node
//
// Entry point into the app
const commandLineArgs = require('command-line-args')
const Tools = require('./tools')
async function main() {
// Fetch name of requested tool
const opts = commandLineArgs([
{ name: 'command', default: 'list-tools', defaultOption: true }
], { stopAtFirstUnknown: true })
try {
// Load tool
const toolName = opts.command || 'about'
const Tool = Tools[toolName]
if (!Tool)
return console.warn(`Tool '${toolName}' was not found.`)
// Parse args for the tool
const argv = opts._unknown || []
const opts2 = commandLineArgs(Tool.args, { argv })
// Run tool
await Tools[toolName].run(opts2)
} catch (err) {
// Check how to log
console.warn(err.message)
}
}
main()