-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcli.js
executable file
·64 lines (49 loc) · 2.01 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
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env node
var usage = 'Usage: asciinema-selfhost --file <asciinema-file>\n'
+ ' asciinema-selfhost --clone <asciinema-id> [<path>]\n'
+ ' asciinema-selfhost --rehost <asciinema-id>\n\n'
+ 'Clone asciinemas as small static websites, and then self host them\n'
+ 'on any webserver. Or use --rehost to publish them straight to ipfs!'
var as = require('./')
var opt = require('optimist')
.usage(usage)
.boolean('h').alias('h', 'help').describe('h', 'show this help output')
.boolean('f').alias('f', 'file').describe('f', 'host asciinema from file in ipfs')
.boolean('c').alias('c', 'clone').describe('c', 'clone asciinema')
.boolean('r').alias('r', 'rehost').describe('r', 'rehost asciinema to ipfs')
.boolean('j').alias('j', 'json').describe('j', 'fetch asciinema.json')
.boolean('s').alias('s', 'size').describe('s', 'fetch asciinema size')
if (opt.argv.h || opt.argv._.length < 1) {
process.stdout.write(opt.help())
process.exit(0)
}
if (opt.argv.j) {
as.getAsciinemaJSON(opt.argv._[0], function(err, data) {
if (err) throw err
process.stdout.write(JSON.stringify(data))
process.stdout.write('\n')
})
} else if (opt.argv.f) {
as.hostAsciinemaFile(opt.argv._[0], function(err, hash) {
if (err) throw err
console.log('view locally at http://localhost:8080/ipfs/' + hash)
console.log('view globally at http://gateway.ipfs.io/ipfs/' + hash)
})
} else if (opt.argv.s) {
as.getAsciinemaSize(opt.argv._[0], function(err, data) {
if (err) throw err
process.stdout.write(JSON.stringify(data))
process.stdout.write('\n')
})
} else if (opt.argv.c) {
var path = (opt.argv._.length > 1) ? opt.argv._[1] : null
as.cloneAsciinema(opt.argv._[0], path, function(err, data) {
if (err) throw err
})
} else if (opt.argv.r) {
as.rehostAsciinema(opt.argv._[0], function(err, hash) {
if (err) throw err
console.log('view locally at http://localhost:8080/ipfs/' + hash)
console.log('view globally at http://gateway.ipfs.io/ipfs/' + hash)
})
}