-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbigmap-cli
More file actions
executable file
·156 lines (137 loc) · 5.4 KB
/
bigmap-cli
File metadata and controls
executable file
·156 lines (137 loc) · 5.4 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env node
const fs = require("fs");
const bigmap = require('./cli/bigmap_cli.js');
const yargs = require("yargs");
const options = yargs
.usage("Usage: $0 <cmd> [args]")
.option("get", { describe: "Get key; start with @ to load from file", type: "string", requiresArg: true, nargs: 1, demandOption: false })
.option("o", { describe: "Output filename for the --get command", type: "string", requiresArg: true, nargs: 1, demandOption: false })
.option("put", { describe: "Put value for given key", type: "array", requiresArg: true, nargs: 2, demandOption: false })
.option("put-and-fts-index", { describe: "Put value and add to the FTS index", type: "array", requiresArg: true, nargs: 2, demandOption: false })
.option("put-and-fts-index-file", { describe: "Put and FTS index data from file", type: "string", requiresArg: true, nargs: 1, demandOption: false })
.option("remove_from-fts-index", { describe: "Remove key from the search index", type: "string", requiresArg: true, nargs: 1, demandOption: false })
.option("append", { describe: "Append to the value for given key", type: "array", requiresArg: true, nargs: 2, demandOption: false })
.option("delete", { describe: "Delete the given key", type: "string", requiresArg: true, nargs: 1, demandOption: false })
.option("list", { describe: "List keys with the given prefix", type: "array", requiresArg: false, demandOption: false })
.option("maintenance", { describe: "Run maintenance", type: "bool", nargs: 0, demandOption: false })
.option("status", { describe: "Get status of the BigMap deployment", type: "bool", nargs: 0, demandOption: false })
.option("set-data-bucket-wasm-binary", { describe: "Set Wasm binary for the data buckets, from file", type: "string", requiresArg: true, nargs: 1, demandOption: false })
.option("set-search-wasm-binary", { describe: "Set Wasm binary for the search canisters, from file", type: "string", requiresArg: true, nargs: 1, demandOption: false })
.option("search", { describe: "Search for the terms", type: "array", requiresArg: true, requiresArg: true, demandOption: false })
.option("call-index", { describe: "Call an index canister function", type: "array", requiresArg: true, demandOption: false })
.option("call-data", { describe: "Call a data canister function", type: "array", requiresArg: true, demandOption: false })
.showHelpOnFail(false, "Specify --help for available options")
.argv;
if (options.get) {
let key = options.get;
if (key[0] == '@') {
key = fs.readFileSync(key.substring(1));
}
if (options.o) {
bigmap.getToFile(key, options.o);
} else {
bigmap.get(key);
}
}
if (options.put) {
if (options.put.length == 2) {
let key = options.put[0];
let value = options.put[1];
if (key[0] == '@') {
key = fs.readFileSync(key.substring(1));
}
if (value[0] == '@') {
value = fs.readFileSync(value.substring(1));
}
bigmap.put(key, value);
} else {
console.log("Put requires exactly two arguments: key value");
}
}
if (options.append) {
if (options.append.length == 2) {
let key = options.append[0];
let value = options.append[1];
if (key[0] == '@') {
key = fs.readFileSync(key.substring(1));
}
if (value[0] == '@') {
value = fs.readFileSync(value.substring(1));
}
bigmap.append(key, value);
} else {
console.log("Append requires exactly two arguments: key value");
}
}
if (options.delete) {
let key = options.delete;
if (key[0] == '@') {
key = fs.readFileSync(key.substring(1));
}
bigmap.deleteKey(key);
}
if (options.list) {
// Take only the first argument to '--list'
let key_prefix = (options.list && options.list[0]) || "";
if (key_prefix[0] == '@') {
key_prefix = fs.readFileSync(key_prefix.substring(1));
}
bigmap.list(key_prefix);
}
if (options.setDataBucketWasmBinary) {
bigmap.setDataBucketWasmBinary(options.setDataBucketWasmBinary)
}
if (options.setSearchWasmBinary) {
bigmap.setSearchWasmBinary(options.setSearchWasmBinary)
}
if (options.maintenance) {
bigmap.maintenance()
}
if (options.status) {
bigmap.status()
}
if (options.callIndex) {
if (options.callIndex.length >= 1) {
bigmap.callIndex(options.callIndex[0], options.callIndex.slice(1))
} else {
console.log("--call-index requires 1 or more arguments: <functionName> [arg1 [arg2 [...]]]");
}
}
if (options.callData) {
if (options.callData.length >= 2) {
bigmap.callData(options.callData[0], options.callData[1], options.callData.slice(2))
} else {
console.log("--call-data requires 2 or more arguments: <canisterId> <functionName> [arg1 [arg2 [...]]]");
}
}
if (options.putAndFtsIndex) {
if (options.putAndFtsIndex.length == 2) {
let key = options.putAndFtsIndex[0];
let value = options.putAndFtsIndex[1];
if (key[0] == '@') {
key = fs.readFileSync(key.substring(1));
}
if (value[0] == '@') {
value = fs.readFileSync(value.substring(1));
}
bigmap.put_and_fts_index(key, value);
} else {
console.log("putAndFtsIndex requires exactly two arguments: key value");
}
}
if (options.putAndFtsIndexFile) {
bigmap.put_and_fts_index_file(options.putAndFtsIndexFile);
}
if (options.removeFromFtsIndex) {
let key = options.removeFromFtsIndex;
if (key[0] == '@') {
key = fs.readFileSync(key.substring(1));
}
bigmap.remove_from_fts_index(key);
}
if (options.search) {
bigmap.search(options.search);
}
if (process.argv.length < 3) {
yargs.showHelp()
}