yargs 3.7.1 → 3.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +23 -7
- package/index.js +461 -456
- package/lib/completion.js +29 -29
- package/lib/parser.js +349 -354
- package/lib/usage.js +289 -381
- package/lib/validation.js +186 -187
- package/package.json +19 -20
package/lib/completion.js
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
1
1
|
var fs = require('fs'),
|
|
2
|
-
path = require('path')
|
|
2
|
+
path = require('path')
|
|
3
3
|
|
|
4
4
|
// add bash completions to your
|
|
5
5
|
// yargs-powered applications.
|
|
6
6
|
module.exports = function (yargs, usage) {
|
|
7
7
|
var self = {
|
|
8
8
|
completionKey: 'get-yargs-completions'
|
|
9
|
-
}
|
|
9
|
+
}
|
|
10
10
|
|
|
11
11
|
// get a list of completion commands.
|
|
12
12
|
self.getCompletion = function (done) {
|
|
13
13
|
var completions = [],
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
current = process.argv[process.argv.length - 1],
|
|
15
|
+
previous = process.argv.slice(process.argv.indexOf('--' + self.completionKey) + 1),
|
|
16
|
+
argv = yargs.parse(previous)
|
|
17
17
|
|
|
18
18
|
// a custom completion function can be provided
|
|
19
19
|
// to completion().
|
|
20
20
|
if (completionFunction) {
|
|
21
21
|
if (completionFunction.length < 3) {
|
|
22
22
|
// synchronous completion function.
|
|
23
|
-
return done(completionFunction(current, argv))
|
|
23
|
+
return done(completionFunction(current, argv))
|
|
24
24
|
} else {
|
|
25
25
|
// asynchronous completion function
|
|
26
|
-
return completionFunction(current, argv, function(completions) {
|
|
27
|
-
done(completions)
|
|
28
|
-
})
|
|
26
|
+
return completionFunction(current, argv, function (completions) {
|
|
27
|
+
done(completions)
|
|
28
|
+
})
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
if (!current.match(/^-/)) {
|
|
33
|
-
usage.getCommands().forEach(function(command) {
|
|
34
|
-
completions.push(command[0])
|
|
35
|
-
})
|
|
33
|
+
usage.getCommands().forEach(function (command) {
|
|
34
|
+
completions.push(command[0])
|
|
35
|
+
})
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
if (current.match(/^-/)) {
|
|
39
|
-
Object.keys(yargs.getOptions().key).forEach(function(key) {
|
|
40
|
-
completions.push('--' + key)
|
|
41
|
-
})
|
|
39
|
+
Object.keys(yargs.getOptions().key).forEach(function (key) {
|
|
40
|
+
completions.push('--' + key)
|
|
41
|
+
})
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
done(completions)
|
|
45
|
-
}
|
|
44
|
+
done(completions)
|
|
45
|
+
}
|
|
46
46
|
|
|
47
47
|
// generate the completion script to add to your .bashrc.
|
|
48
48
|
self.generateCompletionScript = function ($0) {
|
|
49
49
|
var script = fs.readFileSync(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
path.resolve(__dirname, '../completion.sh.hbs'),
|
|
51
|
+
'utf-8'
|
|
52
|
+
),
|
|
53
|
+
name = path.basename($0)
|
|
54
54
|
|
|
55
55
|
// add ./to applications not yet installed as bin.
|
|
56
|
-
if ($0.match(/\.js$/)) $0 = './' + $0
|
|
56
|
+
if ($0.match(/\.js$/)) $0 = './' + $0
|
|
57
57
|
|
|
58
|
-
script = script.replace(/{{app_name}}/g, name)
|
|
59
|
-
return script.replace(/{{app_path}}/g, $0)
|
|
60
|
-
}
|
|
58
|
+
script = script.replace(/{{app_name}}/g, name)
|
|
59
|
+
return script.replace(/{{app_path}}/g, $0)
|
|
60
|
+
}
|
|
61
61
|
|
|
62
62
|
// register a function to perform your own custom
|
|
63
63
|
// completions., this function can be either
|
|
64
64
|
// synchrnous or asynchronous.
|
|
65
|
-
var completionFunction = null
|
|
65
|
+
var completionFunction = null
|
|
66
66
|
self.registerFunction = function (fn) {
|
|
67
|
-
|
|
67
|
+
completionFunction = fn
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
return self
|
|
71
|
-
}
|
|
70
|
+
return self
|
|
71
|
+
}
|