-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
59 lines (55 loc) · 1.31 KB
/
index.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
54
55
56
57
58
59
#!/usr/bin/env node
const yargs = require('yargs')
const download = require('../lib')
const argv = yargs
.usage('$0', 'Download an hash via IPFS, falling back to an HTTP Gateway.')
.scriptName('ipfs-or-gateway')
.option('cid', {
alias: 'c',
describe: 'cid to download',
type: 'string',
demandOption: true
}).option('path', {
alias: 'p',
describe: 'path to output the files',
type: 'string',
demandOption: true
}).option('clean', {
describe: 'clean path first',
type: 'boolean',
default: false
}).option('archive', {
describe: 'output a TAR archive',
type: 'boolean',
default: false
}).option('compress', {
describe: 'compress the archive with GZIP compression',
type: 'boolean',
default: false
}).option('api', {
alias: 'a',
describe: 'api url',
type: 'string',
default: 'https://ipfs.io/api'
}).option('retries', {
alias: 'r',
describe: 'number of retries for each gateway',
type: 'number',
default: 3
}).option('timeout', {
alias: 't',
describe: 'timeout of request without data from the server',
type: 'number',
default: 60000
})
.help()
.argv
async function run () {
try {
await download(argv)
} catch (error) {
console.error(error.toString())
process.exit(1)
}
}
run()