@@ -22,35 +22,37 @@ commander.version(pkg.version)
22
22
. option ( '--public [key]' , 'keymetrics public key' )
23
23
. option ( '--machine-name [name]' , 'keymetrics machine name' )
24
24
. option ( '--auto-exit' , 'exit if all processes are errored/stopped or 0 apps launched' )
25
+ . option ( '--env [name]' , 'select env_[name] env variables in process config file' )
26
+ . option ( '--watch' , 'Watch and Restart' )
25
27
. usage ( 'start <app>' ) ;
26
28
29
+ function start ( cmd , opts ) {
30
+ pm2 = new PM2 . custom ( {
31
+ pm2_home : path . join ( process . env . HOME , '.pm2' ) ,
32
+ secret_key : process . env . KEYMETRICS_SECRET || commander . secret ,
33
+ public_key : process . env . KEYMETRICS_PUBLIC || commander . public ,
34
+ machine_name : process . env . INSTANCE_NAME || commander . machineName ,
35
+ daemon_mode : true
36
+ } ) ;
37
+
38
+ if ( commander . autoExit )
39
+ autoExit ( ) ;
40
+
41
+ pm2 . connect ( function ( ) {
42
+ run ( cmd , opts ) ;
43
+ } ) ;
44
+ }
45
+
27
46
commander . command ( '*' )
28
- . action ( function ( cmd , opts ) {
29
- console . error ( 'Unknown command argument' ) ;
30
- commander . outputHelp ( ) ;
47
+ . action ( function ( cmd ) {
48
+ start ( cmd , commander ) ;
31
49
} ) ;
32
50
33
51
// @todo need to allow passing same option than pm2 start
34
52
commander . command ( 'start <file|json_file>' )
35
- . option ( '--env [name]' , 'select env_[name] env variables in process config file' )
36
- . option ( '--watch' , 'Watch and Restart' )
37
53
. description ( 'start json_file or application' )
38
- . action ( function ( cmd , opts ) {
39
-
40
- pm2 = new PM2 . custom ( {
41
- pm2_home : path . join ( process . env . HOME , '.pm2' ) ,
42
- secret_key : process . env . KEYMETRICS_SECRET || commander . secret ,
43
- public_key : process . env . KEYMETRICS_PUBLIC || commander . public ,
44
- machine_name : process . env . INSTANCE_NAME || commander . machineName ,
45
- daemon_mode : true
46
- } ) ;
47
-
48
- if ( commander . autoExit )
49
- autoExit ( ) ;
50
-
51
- pm2 . connect ( function ( ) {
52
- run ( cmd , opts ) ;
53
- } ) ;
54
+ . action ( function ( cmd ) {
55
+ start ( cmd , commander ) ;
54
56
} ) ;
55
57
56
58
if ( process . argv . length == 2 ) {
0 commit comments