-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
30 lines (27 loc) · 905 Bytes
/
cli.js
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
#!/usr/bin/env node
const prog = require('caporal'),
server = require('home-file-server'),
net = require('net'),
{ address } = require('ip'),
dns = require('dns'),
colors = require('colors')
function reverseLookup(ip, callback) {
let domain
dns.reverse(ip, function (err, domains) {
callback(domains ? domains[0] : undefined)
})
}
prog
.version('1.0.0')
.command('start', 'Start a web server')
.argument('[path]', 'Shared folder relative path', null, '.')
.action(function (args, options, logger) {
let homeServer = new server.homeServer(args.path)
homeServer.start()
})
.command('scan', 'Find all running web servers on network')
.action(function (args, options, logger) {
logger.info(colors.green('Found following devices:'))
server.utils.scan(host => server.utils.reverseLookup(host, d => logger.info(`${colors.green(d)}: http://${host}:8080`)))
})
prog.parse(process.argv)