-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·69 lines (53 loc) · 1.7 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
65
66
67
68
69
#!/usr/bin/env node
var hypergraphCli = require('./index.js')
var minimist = require('minimist')
var fs = require('fs')
var keys = ['subject', 'predicate', 'object']
var argv = minimist(process.argv.slice(2), {string: keys})
var command = argv._[0]
var dirs, query
if (command === 'hyperreadings') {
var path = require('os').homedir() + '/hyper-readings'
if (!fs.existsSync(path)) exit('Hyperreadings not found.')
dirs = fs.readdirSync(path).map((name) => ({name: name, path: path + '/' + name}))
query = {predicate: 'rdf:type', object: 'hr:root'}
} else if (command === 'browse') {
path = argv._[1]
if (!path) {
exit('Path to hypergraph database is required.')
} else if (!fs.existsSync(path) || !fs.lstatSync(path).isDirectory()) {
exit('Path not found.')
}
dirs = [path]
query = Object.keys(argv).filter((key) => keys.includes(key)).reduce((obj, key) => {
obj[key] = argv[key]
return obj
}, {})
if (Object.keys(query).length < 1) {
exit('Pass at least 1 out of subject, preciate, object options.')
}
} else {
usage()
}
hypergraphCli(dirs, query)
function exit (msg) {
console.error(msg)
process.exit(1)
}
function usage () {
console.log(`Usage: hyper-graph-cli COMMAND [args] [options]
Browse a hyper-graph-db by path:
$ hyper-graph-cli browse PATH [options]
where PATH is the path to a hyper-graph database directory.
Pass at least one out of the three query options:
--subject
--predicate
--object
This sets the properties of the root query.
Browse installed hyperreadings databases:
$ hyper-graph-cli hyperreadings
This assumes that databases created or shared via
hyper-reader are to be found in $HOME/hyper-readings.
`)
process.exit(0)
}