@waron97/prbot 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +78 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -7,7 +7,9 @@ import path from "path";
|
|
|
7
7
|
import { execFile } from "child_process";
|
|
8
8
|
import { program } from "commander";
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
if (process.argv[2] !== "completion") {
|
|
11
|
+
configDotenv({ path: path.join(process.env.HOME, ".prbot") });
|
|
12
|
+
}
|
|
11
13
|
|
|
12
14
|
async function getToken() {
|
|
13
15
|
const url = process.env.KC_URL;
|
|
@@ -77,6 +79,12 @@ async function main(module_name) {
|
|
|
77
79
|
`[${file.name}] Export contains skipped records:\n${footer.trim()}`,
|
|
78
80
|
);
|
|
79
81
|
}
|
|
82
|
+
const duplicatedMatch = footer.match(/Duplicated records:\s*(\d+)/);
|
|
83
|
+
if (duplicatedMatch && parseInt(duplicatedMatch[1]) > 0) {
|
|
84
|
+
throw new Error(
|
|
85
|
+
`[${file.name}] Export contains duplicated records:\n${footer.trim()}`,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
80
88
|
}
|
|
81
89
|
|
|
82
90
|
if (lines.length > 2) {
|
|
@@ -246,6 +254,75 @@ program
|
|
|
246
254
|
});
|
|
247
255
|
});
|
|
248
256
|
|
|
257
|
+
program
|
|
258
|
+
.command("completion [shell]")
|
|
259
|
+
.description("Print shell completion script")
|
|
260
|
+
.action((shell = "bash") => {
|
|
261
|
+
if (shell === "bash") {
|
|
262
|
+
process.stdout.write(`
|
|
263
|
+
_prbot_completion() {
|
|
264
|
+
local cur prev
|
|
265
|
+
COMPREPLY=()
|
|
266
|
+
cur="\${COMP_WORDS[COMP_CWORD]}"
|
|
267
|
+
prev="\${COMP_WORDS[COMP_CWORD-1]}"
|
|
268
|
+
|
|
269
|
+
if [[ "\$prev" == "-m" || "\$prev" == "--module" ]]; then
|
|
270
|
+
local addons_path
|
|
271
|
+
addons_path=\$(grep -E '^ADDONS_PATH=' ~/.prbot 2>/dev/null | head -1 | cut -d= -f2- | sed "s|~|\$HOME|g")
|
|
272
|
+
if [[ -n "\$addons_path" && -d "\$addons_path/config" ]]; then
|
|
273
|
+
local modules
|
|
274
|
+
modules=\$(ls -1 "\$addons_path/config" 2>/dev/null)
|
|
275
|
+
COMPREPLY=(\$(compgen -W "\$modules" -- "\$cur"))
|
|
276
|
+
fi
|
|
277
|
+
return 0
|
|
278
|
+
fi
|
|
279
|
+
|
|
280
|
+
COMPREPLY=(\$(compgen -W "pr ver completion" -- "\$cur"))
|
|
281
|
+
}
|
|
282
|
+
complete -F _prbot_completion prbot
|
|
283
|
+
`);
|
|
284
|
+
} else if (shell === "zsh") {
|
|
285
|
+
process.stdout.write(`
|
|
286
|
+
#compdef prbot
|
|
287
|
+
|
|
288
|
+
_prbot() {
|
|
289
|
+
local state
|
|
290
|
+
_arguments \\
|
|
291
|
+
'1: :->command' \\
|
|
292
|
+
'*: :->args'
|
|
293
|
+
|
|
294
|
+
case \$state in
|
|
295
|
+
command)
|
|
296
|
+
_values 'command' 'pr' 'ver' 'completion'
|
|
297
|
+
;;
|
|
298
|
+
args)
|
|
299
|
+
case \${words[2]} in
|
|
300
|
+
pr|ver)
|
|
301
|
+
case \${words[CURRENT-1]} in
|
|
302
|
+
-m|--module)
|
|
303
|
+
local addons_path
|
|
304
|
+
addons_path=\$(grep -E '^ADDONS_PATH=' ~/.prbot 2>/dev/null | head -1 | cut -d= -f2- | sed "s|~|\$HOME|g")
|
|
305
|
+
if [[ -n "\$addons_path" && -d "\$addons_path/config" ]]; then
|
|
306
|
+
local -a modules
|
|
307
|
+
modules=(\$(ls -1 "\$addons_path/config" 2>/dev/null))
|
|
308
|
+
_describe 'module' modules
|
|
309
|
+
fi
|
|
310
|
+
;;
|
|
311
|
+
esac
|
|
312
|
+
;;
|
|
313
|
+
esac
|
|
314
|
+
;;
|
|
315
|
+
esac
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
_prbot
|
|
319
|
+
`);
|
|
320
|
+
} else {
|
|
321
|
+
console.error(`Unsupported shell: ${shell}. Use 'bash' or 'zsh'.`);
|
|
322
|
+
process.exit(1);
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
|
|
249
326
|
program
|
|
250
327
|
.command("ver")
|
|
251
328
|
.option("-m, --module <module>")
|