Repository navigation
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·59 lines (43 loc) · 1.58 KB
/
Copy pathcli.js
File metadata and controls
executable file
·59 lines (43 loc) · 1.58 KB
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
import { pack, cid, download } from "./index.js"
import { Command } from 'commander'
async function packDirectory(dir, archivePath) {
await pack(dir, archivePath)
const rootCid = await cid(archivePath)
console.log(`CID: ${rootCid}`)
process.exit(0)
}
async function printCid(archivePath) {
const rootCid = await cid(archivePath)
console.log(`CID: ${rootCid}`)
process.exit(0)
}
export async function downloadData(dir, archivePath, cid, urls, options) {
await download(dir, archivePath, cid, urls, options)
process.exit(0)
}
const program = new Command()
program
.name('dam')
.description('Data Archive Manager')
program.command('pack')
.description('pack contents of a data directory into a .tar.gz content archive')
.argument('<dir>', 'input data directory')
.argument('<archive>', 'path to the output .tar.gz archive')
.action(packDirectory)
program.command('cid')
.description('compute the content identifier (CID) for the .tar.gz content archive')
.argument('<archive>', 'path to the .tar.gz archive')
.action(printCid)
program.command('download')
.description('verify local archive with provided cid or download and unpack if not present')
.argument('<dir>', 'output data directory')
.argument('<archive>', 'path to the local .tar.gz archive')
.argument('<cid>', 'expected cid')
.argument('<urls...>', 'one or more urls storing the archive')
.option('-r, --retries <retries>', 'download retries', parseInt)
.option('-v, --verbose', 'print status')
.action(downloadData)
await program
.parseAsync(process.argv)
program.help()