3
3
var Liftoff = require ( 'liftoff' )
4
4
, v8flags = require ( 'v8flags' )
5
5
, semver = require ( 'semver' )
6
- , extend = require ( 'util-extend' )
7
6
, cliPackage = require ( '../package' )
8
- , logger = require ( '../lib/logger' ) ( )
9
- , yargs = require ( 'yargs' ) ;
7
+ , nopt = require ( 'nopt' ) ;
10
8
11
- var argv = yargs
12
- . usage ( 'Usage: $0 [task:]destination [options]' )
13
- . help ( 'help' ) . alias ( 'help' , 'h' )
14
- . version ( cliPackage . version , 'version' ) . alias ( 'version' , 'v' )
15
- . options ( 'flightplan' , {
16
- alias : 'f' ,
17
- //default: 'flightplan.js',
18
- describe : 'path to flightplan'
19
- } )
20
- . options ( 'username' , {
21
- alias : 'u' ,
22
- describe : 'user for connecting to remote hosts'
23
- } )
24
- . options ( 'debug' , {
25
- alias : 'd' ,
26
- describe : 'enable debug mode'
27
- } )
28
- . options ( 'no-color' , {
29
- alias : 'C' ,
30
- describe : 'disable colors in output'
31
- } ) . argv ;
9
+ var knownOptions = {
10
+ 'flightplan' : String ,
11
+ 'username' : String ,
12
+ 'debug' : Boolean ,
13
+ 'color' : Boolean ,
14
+ 'version' : Boolean ,
15
+ 'help' : Boolean
16
+ } ;
17
+
18
+ var shortHands = {
19
+ 'f' : [ '--flightplan' ] ,
20
+ 'u' : [ '--username' ] ,
21
+ 'd' : [ '--debug' ] ,
22
+ 'C' : [ '--no-color' ] ,
23
+ 'v' : [ '--version' ] ,
24
+ 'h' : [ '--help' ]
25
+ } ;
26
+
27
+ var options = nopt ( knownOptions , shortHands , process . argv , 2 ) ;
28
+
29
+ if ( options . help ) {
30
+ console . log ( '\n' +
31
+ ' Usage: fly [task:]destination [options]\n\n' +
32
+ ' Options:\n\n' +
33
+ ' -h, --help output usage information\n' +
34
+ ' -V, --version output the version number\n' +
35
+ ' -f, --flightplan <file> path to flightplan\n' +
36
+ ' -u, --username <name> user for connecting to remote hosts\n' +
37
+ ' -d, --debug enable debug mode\n' +
38
+ ' -C, --no-color disable color output\n'
39
+ ) ;
40
+ process . exit ( 1 ) ;
41
+ }
42
+
43
+ if ( options . version ) {
44
+ console . log ( cliPackage . version ) ;
45
+ process . exit ( 1 ) ;
46
+ }
32
47
33
48
var task = 'default' ;
34
- var target = argv . _ ? argv . _ [ 0 ] : null ;
49
+ var target = options . argv . remain . length ? options . argv . remain [ 0 ] : null ;
35
50
36
51
if ( target && target . indexOf ( ':' ) !== - 1 ) {
37
52
target = target . split ( ':' ) ;
@@ -52,31 +67,31 @@ var cli = new Liftoff({
52
67
53
68
var invoke = function ( env ) {
54
69
if ( ! target ) {
55
- logger . error ( 'Error: No target specified' ) ;
70
+ console . error ( 'Error: No target specified' ) ;
56
71
process . exit ( 1 ) ;
57
72
}
58
73
59
74
if ( ! env . configPath ) {
60
- logger . error ( 'Error: flightplan.js not found' ) ;
75
+ console . error ( 'Error: ' + ( options . flightplan || 'flightplan .js' ) + ' not found') ;
61
76
process . exit ( 1 ) ;
62
77
}
63
78
64
79
if ( ! env . modulePath ) {
65
- logger . error ( 'Error: Local flightplan package not found in ' + env . cwd ) ;
80
+ console . error ( 'Error: Local flightplan package not found in ' + env . cwd ) ;
66
81
process . exit ( 1 ) ;
67
82
}
68
83
69
84
if ( ! semver . satisfies ( env . modulePackage . version , '>=0.5.0' ) ) {
70
- logger . error ( 'Error: local flightplan package version should be >=0.5.0' ) ;
85
+ console . error ( 'Error: local flightplan package version should be >=0.5.0' ) ;
71
86
process . exit ( 1 ) ;
72
87
}
73
88
74
89
process . chdir ( env . configBase ) ;
75
90
require ( env . configPath ) ;
76
91
var instance = require ( env . modulePath ) ;
77
- instance . run ( task , target , argv ) ;
92
+ instance . run ( task , target , options ) ;
78
93
} ;
79
94
80
95
cli . launch ( {
81
- configPath : argv . flightplan
96
+ configPath : options . flightplan
82
97
} , invoke ) ;
0 commit comments