@did-btcr2/cli 0.23.0 → 0.23.1
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/README.md +36 -411
- package/dist/.tsbuildinfo +1 -1
- package/dist/cjs/index.js +11 -6
- package/dist/esm/src/commands/completion.js +20 -7
- package/dist/esm/src/commands/completion.js.map +1 -1
- package/dist/types/src/commands/completion.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/commands/completion.ts +21 -7
package/dist/cjs/index.js
CHANGED
|
@@ -3338,30 +3338,35 @@ function registerProfileCommand(program, globals) {
|
|
|
3338
3338
|
}
|
|
3339
3339
|
|
|
3340
3340
|
// src/commands/completion.ts
|
|
3341
|
-
var
|
|
3341
|
+
var HELP_COMMAND = "help";
|
|
3342
3342
|
function registerCompletionCommand(program, _globals) {
|
|
3343
3343
|
program.command("completion [shell]").description("Print a shell completion script (bash, zsh, or fish) to stdout.").action((shell = "bash") => {
|
|
3344
|
-
console.log(completionScript(shell));
|
|
3344
|
+
console.log(completionScript(shell, completionWords(program)));
|
|
3345
3345
|
});
|
|
3346
3346
|
}
|
|
3347
|
-
function
|
|
3347
|
+
function completionWords(program) {
|
|
3348
|
+
const words = program.commands.flatMap((command) => [command.name(), ...command.aliases()]);
|
|
3349
|
+
return [...words, HELP_COMMAND];
|
|
3350
|
+
}
|
|
3351
|
+
function completionScript(shell, words) {
|
|
3352
|
+
const list = words.join(" ");
|
|
3348
3353
|
switch (shell) {
|
|
3349
3354
|
case "bash":
|
|
3350
3355
|
return [
|
|
3351
3356
|
'# btcr2 bash completion. Install with: eval "$(btcr2 completion bash)"',
|
|
3352
|
-
'_btcr2() { COMPREPLY=( $(compgen -W "' +
|
|
3357
|
+
'_btcr2() { COMPREPLY=( $(compgen -W "' + list + '" -- "${COMP_WORDS[COMP_CWORD]}") ); }',
|
|
3353
3358
|
"complete -F _btcr2 btcr2"
|
|
3354
3359
|
].join("\n");
|
|
3355
3360
|
case "zsh":
|
|
3356
3361
|
return [
|
|
3357
3362
|
'# btcr2 zsh completion. Install with: eval "$(btcr2 completion zsh)"',
|
|
3358
|
-
"_btcr2() { compadd " +
|
|
3363
|
+
"_btcr2() { compadd " + list + " }",
|
|
3359
3364
|
"compdef _btcr2 btcr2"
|
|
3360
3365
|
].join("\n");
|
|
3361
3366
|
case "fish":
|
|
3362
3367
|
return [
|
|
3363
3368
|
"# btcr2 fish completion. Save to ~/.config/fish/completions/btcr2.fish",
|
|
3364
|
-
'complete -c btcr2 -f -a "' +
|
|
3369
|
+
'complete -c btcr2 -f -a "' + list + '"'
|
|
3365
3370
|
].join("\n");
|
|
3366
3371
|
default:
|
|
3367
3372
|
throw new CLIError(`Unsupported shell "${shell}". Use bash, zsh, or fish.`, "INVALID_ARGUMENT_ERROR", { shell });
|
|
@@ -1,33 +1,46 @@
|
|
|
1
1
|
import { CLIError } from '../error.js';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The name of the built-in help command of commander. Commander creates that
|
|
4
|
+
* command at parse time, so `program.commands` does not list it.
|
|
5
|
+
*/
|
|
6
|
+
const HELP_COMMAND = 'help';
|
|
3
7
|
/** Registers the `completion` command, which prints a shell completion script to stdout. */
|
|
4
8
|
export function registerCompletionCommand(program, _globals) {
|
|
5
9
|
program
|
|
6
10
|
.command('completion [shell]')
|
|
7
11
|
.description('Print a shell completion script (bash, zsh, or fish) to stdout.')
|
|
8
12
|
.action((shell = 'bash') => {
|
|
9
|
-
console.log(completionScript(shell));
|
|
13
|
+
console.log(completionScript(shell, completionWords(program)));
|
|
10
14
|
});
|
|
11
15
|
}
|
|
12
|
-
/**
|
|
13
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Returns the completion word list: the name and the aliases of each registered
|
|
18
|
+
* top-level command, in registration order, then the built-in help command.
|
|
19
|
+
*/
|
|
20
|
+
function completionWords(program) {
|
|
21
|
+
const words = program.commands.flatMap((command) => [command.name(), ...command.aliases()]);
|
|
22
|
+
return [...words, HELP_COMMAND];
|
|
23
|
+
}
|
|
24
|
+
/** Returns a completion script for the given shell and word list. */
|
|
25
|
+
function completionScript(shell, words) {
|
|
26
|
+
const list = words.join(' ');
|
|
14
27
|
switch (shell) {
|
|
15
28
|
case 'bash':
|
|
16
29
|
return [
|
|
17
30
|
'# btcr2 bash completion. Install with: eval "$(btcr2 completion bash)"',
|
|
18
|
-
'_btcr2() { COMPREPLY=( $(compgen -W "' +
|
|
31
|
+
'_btcr2() { COMPREPLY=( $(compgen -W "' + list + '" -- "${COMP_WORDS[COMP_CWORD]}") ); }',
|
|
19
32
|
'complete -F _btcr2 btcr2',
|
|
20
33
|
].join('\n');
|
|
21
34
|
case 'zsh':
|
|
22
35
|
return [
|
|
23
36
|
'# btcr2 zsh completion. Install with: eval "$(btcr2 completion zsh)"',
|
|
24
|
-
'_btcr2() { compadd ' +
|
|
37
|
+
'_btcr2() { compadd ' + list + ' }',
|
|
25
38
|
'compdef _btcr2 btcr2',
|
|
26
39
|
].join('\n');
|
|
27
40
|
case 'fish':
|
|
28
41
|
return [
|
|
29
42
|
'# btcr2 fish completion. Save to ~/.config/fish/completions/btcr2.fish',
|
|
30
|
-
'complete -c btcr2 -f -a "' +
|
|
43
|
+
'complete -c btcr2 -f -a "' + list + '"',
|
|
31
44
|
].join('\n');
|
|
32
45
|
default:
|
|
33
46
|
throw new CLIError(`Unsupported shell "${shell}". Use bash, zsh, or fish.`, 'INVALID_ARGUMENT_ERROR', { shell });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"completion.js","sourceRoot":"","sources":["../../../../src/commands/completion.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC,MAAM,
|
|
1
|
+
{"version":3,"file":"completion.js","sourceRoot":"","sources":["../../../../src/commands/completion.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC;;;GAGG;AACH,MAAM,YAAY,GAAG,MAAM,C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B,KAAK,4BAA4B,EAAE,wBAAwB,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IACrH,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"completion.d.ts","sourceRoot":"","sources":["../../../../src/commands/completion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"completion.d.ts","sourceRoot":"","sources":["../../../../src/commands/completion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAQjD,4FAA4F;AAC5F,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,GAAG,IAAI,CAO/F"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@did-btcr2/cli",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "CLI for interacting with did-btcr2-js, the JavaScript/TypeScript reference implementation of the did:btcr2 method. Exposes various parts of multiple packages in the did-btcr2-js monorepo.",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -61,11 +61,11 @@
|
|
|
61
61
|
"@scure/base": "^1.2.6",
|
|
62
62
|
"@web5/dids": "^1.2.0",
|
|
63
63
|
"commander": "^13.1.0",
|
|
64
|
+
"@did-btcr2/key-manager": "^0.7.0",
|
|
64
65
|
"@did-btcr2/api": "^0.23.0",
|
|
65
66
|
"@did-btcr2/common": "^9.4.0",
|
|
66
|
-
"@did-btcr2/
|
|
67
|
-
"@did-btcr2/
|
|
68
|
-
"@did-btcr2/keypair": "^0.13.1"
|
|
67
|
+
"@did-btcr2/keypair": "^0.13.1",
|
|
68
|
+
"@did-btcr2/method": "^0.60.0"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@eslint/js": "^9.21.0",
|
|
@@ -2,7 +2,11 @@ import type { Command } from 'commander';
|
|
|
2
2
|
import { CLIError } from '../error.js';
|
|
3
3
|
import type { GlobalOptions } from '../types.js';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* The name of the built-in help command of commander. Commander creates that
|
|
7
|
+
* command at parse time, so `program.commands` does not list it.
|
|
8
|
+
*/
|
|
9
|
+
const HELP_COMMAND = 'help';
|
|
6
10
|
|
|
7
11
|
/** Registers the `completion` command, which prints a shell completion script to stdout. */
|
|
8
12
|
export function registerCompletionCommand(program: Command, _globals: () => GlobalOptions): void {
|
|
@@ -10,29 +14,39 @@ export function registerCompletionCommand(program: Command, _globals: () => Glob
|
|
|
10
14
|
.command('completion [shell]')
|
|
11
15
|
.description('Print a shell completion script (bash, zsh, or fish) to stdout.')
|
|
12
16
|
.action((shell = 'bash') => {
|
|
13
|
-
console.log(completionScript(shell));
|
|
17
|
+
console.log(completionScript(shell, completionWords(program)));
|
|
14
18
|
});
|
|
15
19
|
}
|
|
16
20
|
|
|
17
|
-
/**
|
|
18
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Returns the completion word list: the name and the aliases of each registered
|
|
23
|
+
* top-level command, in registration order, then the built-in help command.
|
|
24
|
+
*/
|
|
25
|
+
function completionWords(program: Command): string[] {
|
|
26
|
+
const words = program.commands.flatMap((command) => [command.name(), ...command.aliases()]);
|
|
27
|
+
return [...words, HELP_COMMAND];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Returns a completion script for the given shell and word list. */
|
|
31
|
+
function completionScript(shell: string, words: string[]): string {
|
|
32
|
+
const list = words.join(' ');
|
|
19
33
|
switch (shell) {
|
|
20
34
|
case 'bash':
|
|
21
35
|
return [
|
|
22
36
|
'# btcr2 bash completion. Install with: eval "$(btcr2 completion bash)"',
|
|
23
|
-
'_btcr2() { COMPREPLY=( $(compgen -W "' +
|
|
37
|
+
'_btcr2() { COMPREPLY=( $(compgen -W "' + list + '" -- "${COMP_WORDS[COMP_CWORD]}") ); }',
|
|
24
38
|
'complete -F _btcr2 btcr2',
|
|
25
39
|
].join('\n');
|
|
26
40
|
case 'zsh':
|
|
27
41
|
return [
|
|
28
42
|
'# btcr2 zsh completion. Install with: eval "$(btcr2 completion zsh)"',
|
|
29
|
-
'_btcr2() { compadd ' +
|
|
43
|
+
'_btcr2() { compadd ' + list + ' }',
|
|
30
44
|
'compdef _btcr2 btcr2',
|
|
31
45
|
].join('\n');
|
|
32
46
|
case 'fish':
|
|
33
47
|
return [
|
|
34
48
|
'# btcr2 fish completion. Save to ~/.config/fish/completions/btcr2.fish',
|
|
35
|
-
'complete -c btcr2 -f -a "' +
|
|
49
|
+
'complete -c btcr2 -f -a "' + list + '"',
|
|
36
50
|
].join('\n');
|
|
37
51
|
default:
|
|
38
52
|
throw new CLIError(`Unsupported shell "${shell}". Use bash, zsh, or fish.`, 'INVALID_ARGUMENT_ERROR', { shell });
|