@kaynooo/cli-db 0.13.0 → 0.13.2
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/dist/cli.js +81 -2
- package/package.json +5 -5
package/dist/cli.js
CHANGED
|
@@ -593,7 +593,7 @@ class Completing {
|
|
|
593
593
|
}
|
|
594
594
|
var completion = { active: false };
|
|
595
595
|
var OUTPUT_OPTIONS = {
|
|
596
|
-
color: { type: "string", description: "auto (on a terminal alone
|
|
596
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
597
597
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
598
598
|
};
|
|
599
599
|
function applyOutput(color, plain, env = process10.env) {
|
|
@@ -889,6 +889,66 @@ import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs
|
|
|
889
889
|
import { dirname as dirname3, join as join5 } from "path";
|
|
890
890
|
import process15 from "process";
|
|
891
891
|
|
|
892
|
+
// ../kit/src/completions.ts
|
|
893
|
+
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
894
|
+
var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
|
|
895
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
896
|
+
set -l current (commandline -ct)
|
|
897
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
898
|
+
if test "$line" = __files__
|
|
899
|
+
__fish_complete_path $current
|
|
900
|
+
else
|
|
901
|
+
echo $line
|
|
902
|
+
end
|
|
903
|
+
end
|
|
904
|
+
end`;
|
|
905
|
+
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
906
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
907
|
+
local -a lines
|
|
908
|
+
COMPREPLY=()
|
|
909
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
910
|
+
for line in "\${lines[@]}"; do
|
|
911
|
+
if [[ $line == __files__ ]]; then
|
|
912
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
913
|
+
else
|
|
914
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
915
|
+
fi
|
|
916
|
+
done
|
|
917
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
918
|
+
}`;
|
|
919
|
+
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
920
|
+
local line
|
|
921
|
+
local -a described plain
|
|
922
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
923
|
+
if [[ $line == __files__ ]]; then
|
|
924
|
+
_files
|
|
925
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
926
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
927
|
+
else
|
|
928
|
+
plain+=("$line")
|
|
929
|
+
fi
|
|
930
|
+
done
|
|
931
|
+
(( \${#described} )) && _describe -V value described
|
|
932
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
933
|
+
return 0
|
|
934
|
+
}`;
|
|
935
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
936
|
+
if (shell === "fish")
|
|
937
|
+
return `${header}
|
|
938
|
+
${FISH_FUNCTION}
|
|
939
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
940
|
+
`).join("")}`;
|
|
941
|
+
if (shell === "bash")
|
|
942
|
+
return `${header}
|
|
943
|
+
${BASH_FUNCTION}
|
|
944
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
945
|
+
`;
|
|
946
|
+
return `${header}
|
|
947
|
+
${ZSH_FUNCTION}
|
|
948
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
949
|
+
`;
|
|
950
|
+
}
|
|
951
|
+
|
|
892
952
|
// ../kit/src/notify.ts
|
|
893
953
|
import process13 from "process";
|
|
894
954
|
var NOTIFY_AFTER_MS = 1e4;
|
|
@@ -962,7 +1022,11 @@ var LEVEL_OPTIONS = {
|
|
|
962
1022
|
...OUTPUT_OPTIONS,
|
|
963
1023
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
964
1024
|
};
|
|
965
|
-
var TOP_OPTIONS = {
|
|
1025
|
+
var TOP_OPTIONS = {
|
|
1026
|
+
...LEVEL_OPTIONS,
|
|
1027
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
1028
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1029
|
+
};
|
|
966
1030
|
async function commandRows(all, colors) {
|
|
967
1031
|
const commands = shown(all);
|
|
968
1032
|
const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
|
|
@@ -1195,6 +1259,19 @@ async function candidates(scope, defaultCommand, words, before = []) {
|
|
|
1195
1259
|
}
|
|
1196
1260
|
return "commands" in command ? candidates(scopeOf(command.commands, command.extraCommands, command.aliases), undefined, rest, [...before, word]) : leafCandidates(command.run, rest);
|
|
1197
1261
|
}
|
|
1262
|
+
var COMPLETIONS = "--completions";
|
|
1263
|
+
function flagValue([flag = "", ...rest]) {
|
|
1264
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1265
|
+
}
|
|
1266
|
+
function printCompletionScript(name, args) {
|
|
1267
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
1268
|
+
if (shell === undefined || args.length !== 1) {
|
|
1269
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
1270
|
+
return 2;
|
|
1271
|
+
}
|
|
1272
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
1273
|
+
return 0;
|
|
1274
|
+
}
|
|
1198
1275
|
async function printCandidates(found) {
|
|
1199
1276
|
for (const line of await found)
|
|
1200
1277
|
console.log(line);
|
|
@@ -1219,6 +1296,8 @@ async function runCli(cli, argv = scriptArgs()) {
|
|
|
1219
1296
|
const version = cli.version ?? packageVersion();
|
|
1220
1297
|
if (argv[0] === COMPLETE)
|
|
1221
1298
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1299
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1300
|
+
return printCompletionScript(cli.name, flagValue(argv));
|
|
1222
1301
|
const started = performance.now();
|
|
1223
1302
|
const code = await dispatch({ path: [cli.name], header: (colors, about) => `${colors.bold(cli.name)} ${colors.dim(version)} ${about}`, summary: cli.about, ...scopeOf(cli.commands, cli.extraCommands, cli.aliases), defaultCommand: cli.defaultCommand, runBare: cli.runBare === true, examples: cli.examples, replaces: cli.replaces }, argv, { version, redact: cli.redact });
|
|
1224
1303
|
const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-db",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.13.
|
|
4
|
+
"version": "0.13.2",
|
|
5
5
|
"description": "db: run read-only SQL against Postgres, MySQL and MariaDB from the terminal without ever showing the connection credentials.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"homepage": "https://
|
|
8
|
+
"homepage": "https://github.com/Kayno0o/cli/tree/main/packages/db#readme",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://
|
|
11
|
+
"url": "git+https://github.com/Kayno0o/cli.git",
|
|
12
12
|
"directory": "packages/db"
|
|
13
13
|
},
|
|
14
|
-
"bugs": "https://
|
|
14
|
+
"bugs": "https://github.com/Kayno0o/cli/issues",
|
|
15
15
|
"keywords": ["postgres", "mysql", "mariadb", "sql", "read-only", "cli", "bun"],
|
|
16
16
|
"bin": {
|
|
17
17
|
"db": "./dist/cli.js"
|
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
"db": "$npm_execpath src/cli.ts"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@kaynooo/cli-kit": "0.
|
|
31
|
+
"@kaynooo/cli-kit": "0.41.0"
|
|
32
32
|
}
|
|
33
33
|
}
|