@@ -82,7 +82,43 @@ program
8282 . option (
8383 "-k, --markerIconOptions <json string>" ,
8484 "Set marker icon options (see doc in https://leafletjs.com/reference-1.6.0.html#icon-option)"
85- ) ;
85+ )
86+ . action ( function ( cmd ) {
87+ const opts = cmd . opts ( ) ;
88+
89+ // DEBUG
90+ // process.stderr.write(JSON.stringify(opts, undefined, 2));
91+ // process.stderr.write("\n");
92+
93+ if ( ! [ "png" , "jpeg" ] . includes ( opts . type ) ) {
94+ process . stderr . write (
95+ '-F|--type can only have the values "png" or "jpeg"\n'
96+ ) ;
97+ process . exit ( 2 ) ;
98+ }
99+
100+ osmsm ( opts )
101+ . then ( v => {
102+ process . stdout . write ( v ) ;
103+ process . stdout . end ( ) ;
104+ process . exit ( 0 ) ;
105+ } )
106+ . catch ( e => {
107+ process . stderr . write ( e . toString ( ) ) ;
108+ process . exit ( 1 ) ;
109+ } ) ;
110+ } ) ;
111+
112+ program
113+ . command ( "serve" )
114+ . option ( "-p, --port <number>" , "Port number to listen" )
115+ . action ( function ( cmd ) {
116+ const server = require ( "./server" ) ;
117+ const port = cmd . port || process . env . PORT || 3000 ;
118+ server . listen ( port , function ( ) {
119+ console . log ( "osmsm server listening on port " + port ) ;
120+ } ) ;
121+ } ) ;
86122
87123program . on ( "--help" , function ( ) {
88124 process . stdout . write ( "\n" ) ;
@@ -97,25 +133,3 @@ program.on("--help", function() {
97133} ) ;
98134
99135program . parse ( process . argv ) ;
100-
101- const opts = program . opts ( ) ;
102-
103- // DEBUG
104- // process.stderr.write(JSON.stringify(opts, undefined, 2));
105- // process.stderr.write("\n");
106-
107- if ( ! [ "png" , "jpeg" ] . includes ( opts . type ) ) {
108- process . stderr . write ( '-F|--type can only have the values "png" or "jpeg"\n' ) ;
109- process . exit ( 2 ) ;
110- }
111-
112- osmsm ( opts )
113- . then ( v => {
114- process . stdout . write ( v ) ;
115- process . stdout . end ( ) ;
116- process . exit ( 0 ) ;
117- } )
118- . catch ( e => {
119- process . stderr . write ( e . toString ( ) ) ;
120- process . exit ( 1 ) ;
121- } ) ;
0 commit comments