-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
executable file
·53 lines (44 loc) · 1.48 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
var argv = require('minimist')(process.argv.slice(2), {
alias: {
u: 'uuid',
t: 'token',
o: 'output'
}
})
var fs = require('fs')
var lion = require('./lion')
var JSONStream = require('JSONStream')
var digitalCollections = require('./')
var errors = []
var uuid = argv.u
var token = argv.t || process.env.DIGITAL_COLLECTIONS_TOKEN
if (!token || typeof (token) !== 'string') {
errors.push('Error: please supply an NYPL API token with the -t option, or set the DIGITAL_COLLECTIONS_TOKEN environment variable')
token = null
}
if (!uuid || typeof (uuid) !== 'string') {
errors.push('Error: please supply a UUID with the -u option')
uuid = null
}
if (process.stdin.isTTY && !(token && uuid)) {
console.error(lion.join('\n') + '\n')
console.error('NYPL Digital Collections API client - see https://github.com/nypl-publicdomain/api-client\n' +
'\n' +
'Usage: digital-collections -t API-TOKEN -u UUID [-o file] \n' +
' -u, --uuid UUID of item or collection\n' +
' -t, --token API access token, see http://api.repo.nypl.org/\n' +
' -o, --output output file, default is stdout\n' +
'\n' +
'Go to http://digitalcollections.nypl.org/ to browse NYPL\'s Digital Collections')
if (errors.length) {
console.error('\n' + errors.join('\n'))
}
process.exit(1)
}
digitalCollections.captures({
uuid: uuid,
token: token
})
.pipe(JSONStream.stringify())
.pipe(argv.o ? fs.createWriteStream(argv.o, 'utf8') : process.stdout)