33'use strict'
44
55const program = require ( 'commander' )
6- const netroute = require ( 'netroute' )
76
87const API = require ( './api' )
98
@@ -15,31 +14,40 @@ const collection = (value, store = []) => {
1514const unique = ( array ) => [ ...new Set ( array ) ]
1615
1716program
18- . version ( '0.1.0' )
19- . arguments ( '<interface> [options]' )
17+ . version ( '0.2.0' )
18+ . arguments ( '[options]' )
19+ . option ( '-g, --gateway <gateway>' , 'Set the gateway address' )
2020 . option ( '--wifi-ssid <wifi-ssid>' , 'WIFI AP name' )
2121 . option ( '--wifi-pass <wifi-pass>' , 'WIFI AP password' )
2222 . option ( '--mqtt <mqtt-server>' , 'MQTT server address' , collection )
2323
2424program . parse ( process . argv ) ;
2525
2626
27- if ( ! program . args . length ) {
28- console . error ( 'interface must be specified' ) ;
27+ if ( ! program . gateway ) {
28+ console . error ( 'Gateway must be specified' ) ;
2929 process . exit ( 1 ) ;
3030}
3131
32- ( async ( ) => {
33- const iface = program . args [ 0 ]
34- const gateway = netroute . getGateway ( iface )
32+ if ( ! program . wifiSsid ) {
33+ console . error ( 'WIFI ssid must be specified' ) ;
34+ process . exit ( 1 ) ;
35+ }
3536
36- console . log ( `Setting up device with IP ${ gateway } on ${ iface } ` )
37+ if ( ! program . wifiPass ) {
38+ console . error ( 'WIFI password must be specified' ) ;
39+ process . exit ( 1 ) ;
40+ }
41+
42+ ( async ( ) => {
43+ const gateway = program . gateway
44+ console . log ( `Setting up device with IP ${ gateway } ` )
3745
3846
3947 const api = new API ( gateway )
4048 var response ;
4149
42- if ( program . mqtt . length ) {
50+ if ( program . mqtt && program . mqtt . length ) {
4351 response = await api . configureMqttServers ( unique ( program . mqtt ) )
4452 }
4553
0 commit comments