-
Notifications
You must be signed in to change notification settings - Fork 6
/
cli.js
executable file
·53 lines (48 loc) · 1.26 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env node
'use strict'
var pack = require('./package.json')
var similarity = require('.')
var argv = process.argv.slice(2)
var sensitives = ['--sensitive', '-s']
var sensitive = false
sensitives.forEach(function(flag) {
var pos = argv.indexOf(flag)
if (pos !== -1) {
argv.splice(pos, 1)
sensitive = true
}
})
if (argv.includes('--help') || argv.includes('-h')) {
console.log(help())
} else if (argv.includes('--version') || argv.includes('-v')) {
console.log(pack.version)
} else if (argv.length === 2) {
process.stdout.write(
String(similarity(argv[0], argv[1], {sensitive: sensitive}))
)
} else {
process.stderr.write(help())
process.exit(1)
}
function help() {
return [
'',
' Usage: ' + pack.name + ' [options] <word> <word>',
'',
' ' + pack.description,
'',
' Options:',
'',
' -h, --help output usage information',
' -v, --version output version number',
' -s, --sensitive be sensitive to casing differences',
'',
' Usage:',
'',
' # output similarity',
' $ ' + pack.name + ' sitting kitten',
' ' + similarity('sitting', 'kitten'),
' $ ' + pack.name + ' saturday sunday',
' ' + similarity('saturday', 'sunday')
].join('\n')
}