@usagefleet/cli 1.2.71 → 1.2.72
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 +8 -0
- package/dist/completion.js +56 -0
- package/dist/index.js +15 -14
- package/dist/release.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,6 +40,14 @@ usagefleet update # upgrade now (it also self-updates every 6h)
|
|
|
40
40
|
usagefleet config # config file location + every env override
|
|
41
41
|
usagefleet install # (re)install the background service, idempotent
|
|
42
42
|
usagefleet uninstall # remove it
|
|
43
|
+
usagefleet completion zsh # print a shell completion script (zsh, fish)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Completions are printed, not installed — send them where your shell looks:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
usagefleet completion zsh > ~/.zsh/completions/_usagefleet # a dir on your fpath
|
|
50
|
+
usagefleet completion fish > ~/.config/fish/completions/usagefleet.fish
|
|
43
51
|
```
|
|
44
52
|
|
|
45
53
|
## What it collects
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** The command list, shared by `help` and the generated completion scripts, so
|
|
2
|
+
* a new command can't land in one and be missing from the other. `args` is the
|
|
3
|
+
* hint `help` prints after the name; completion only needs the bare name. */
|
|
4
|
+
export const commands = [
|
|
5
|
+
{ name: 'run', meaning: 'scan once, upload usage + report limits' },
|
|
6
|
+
{ name: 'watch', args: '[--interval s]', meaning: 'poll continuously (default 15s)' },
|
|
7
|
+
{ name: 'limits', meaning: 'report only your real 5h/weekly usage' },
|
|
8
|
+
{ name: 'guard', meaning: 'exit 2 when the group is over a blocking limit' },
|
|
9
|
+
{ name: 'update', meaning: 'update to the latest release now' },
|
|
10
|
+
{ name: 'notify-test', meaning: 'fire a test desktop notification' },
|
|
11
|
+
{ name: 'status', meaning: 'service health, limits, resolved config' },
|
|
12
|
+
{ name: 'config', meaning: 'config file location and env overrides' },
|
|
13
|
+
{ name: 'completion', args: '<zsh|fish>', meaning: 'print a shell completion script' },
|
|
14
|
+
{ name: 'version', meaning: 'print the release version' },
|
|
15
|
+
{ name: 'install', args: '--token <t>', meaning: 'configure + install the service and prompt guard' },
|
|
16
|
+
{ name: 'uninstall', meaning: 'remove the service and the guard' },
|
|
17
|
+
];
|
|
18
|
+
export const shells = ['zsh', 'fish'];
|
|
19
|
+
/** A completion script for `shell`, on stdout — the user decides where it goes
|
|
20
|
+
* (`> ~/.zsh/completions/_usagefleet`, `> ~/.config/fish/completions/…`).
|
|
21
|
+
* Writing those files ourselves would mean guessing at fpath and rc files. */
|
|
22
|
+
export function completionScript(shell) {
|
|
23
|
+
return shell === 'zsh' ? zsh() : fish();
|
|
24
|
+
}
|
|
25
|
+
function zsh() {
|
|
26
|
+
// zsh splits a _describe entry on the first colon, so any colon in the text
|
|
27
|
+
// has to be escaped or the description gets cut in half.
|
|
28
|
+
const rows = commands.map(c => `\t\t'${c.name}:${c.meaning.replaceAll(':', '\\:')}'`).join('\n');
|
|
29
|
+
return `#compdef usagefleet
|
|
30
|
+
|
|
31
|
+
_usagefleet() {
|
|
32
|
+
local -a commands
|
|
33
|
+
commands=(
|
|
34
|
+
${rows}
|
|
35
|
+
)
|
|
36
|
+
if (( CURRENT == 2 )); then
|
|
37
|
+
_describe 'command' commands
|
|
38
|
+
elif [[ $words[2] == completion ]]; then
|
|
39
|
+
_values 'shell' ${shells.join(' ')}
|
|
40
|
+
fi
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
_usagefleet "$@"
|
|
44
|
+
`;
|
|
45
|
+
}
|
|
46
|
+
function fish() {
|
|
47
|
+
const quote = (s) => s.replaceAll("'", "\\'");
|
|
48
|
+
const rows = commands
|
|
49
|
+
.map(c => `complete -c usagefleet -n __fish_use_subcommand -a ${c.name} -d '${quote(c.meaning)}'`)
|
|
50
|
+
.join('\n');
|
|
51
|
+
// -f: no file completion, this CLI takes no paths.
|
|
52
|
+
return `complete -c usagefleet -f
|
|
53
|
+
${rows}
|
|
54
|
+
complete -c usagefleet -n '__fish_seen_subcommand_from completion' -a '${shells.join(' ')}'
|
|
55
|
+
`;
|
|
56
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { detectClaudeCreds } from './claude-creds.js';
|
|
3
3
|
import { reportLimitsOnce, runOnce } from './collector.js';
|
|
4
|
+
import { commands, completionScript, shells } from './completion.js';
|
|
4
5
|
import { loadConfig } from './config.js';
|
|
5
6
|
import { runGuard } from './guard.js';
|
|
6
7
|
import { loadNotifyConfig } from './notifier.js';
|
|
@@ -248,24 +249,21 @@ function cmdConfig() {
|
|
|
248
249
|
console.log('');
|
|
249
250
|
console.log(hint('`usagefleet status` shows the resolved values'));
|
|
250
251
|
}
|
|
252
|
+
/** Print a completion script, or the shells we know how to write one for. */
|
|
253
|
+
function cmdCompletion() {
|
|
254
|
+
const shell = process.argv[3];
|
|
255
|
+
if (!shells.includes(shell)) {
|
|
256
|
+
console.error(fail('completion', `expected one of ${shells.join(', ')}`));
|
|
257
|
+
process.exitCode = 1;
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
console.log(completionScript(shell));
|
|
261
|
+
}
|
|
251
262
|
/** Command list, in the same padded-column style as the result lines. */
|
|
252
263
|
function help() {
|
|
253
|
-
const commands = [
|
|
254
|
-
['run', 'scan once, upload usage + report limits'],
|
|
255
|
-
['watch [--interval s]', 'poll continuously (default 15s)'],
|
|
256
|
-
['limits', 'report only your real 5h/weekly usage'],
|
|
257
|
-
['guard', 'exit 2 when the group is over a blocking limit'],
|
|
258
|
-
['update', 'update to the latest release now'],
|
|
259
|
-
['notify-test', 'fire a test desktop notification'],
|
|
260
|
-
['status', 'service health, limits, resolved config'],
|
|
261
|
-
['config', 'config file location and env overrides'],
|
|
262
|
-
['version', 'print the release version'],
|
|
263
|
-
['install --token <t>', 'configure + install the service and prompt guard'],
|
|
264
|
-
['uninstall', 'remove the service and the guard'],
|
|
265
|
-
];
|
|
266
264
|
console.log(header());
|
|
267
265
|
console.log('');
|
|
268
|
-
print(commands);
|
|
266
|
+
print(commands.map(c => [c.args ? `${c.name} ${c.args}` : c.name, c.meaning]));
|
|
269
267
|
console.log('');
|
|
270
268
|
console.log(hint('`usagefleet config` lists the config file and its env overrides'));
|
|
271
269
|
}
|
|
@@ -309,6 +307,9 @@ async function main() {
|
|
|
309
307
|
case 'config': {
|
|
310
308
|
return cmdConfig();
|
|
311
309
|
}
|
|
310
|
+
case 'completion': {
|
|
311
|
+
return cmdCompletion();
|
|
312
|
+
}
|
|
312
313
|
// Bare version, so the installer can compare builds without parsing help.
|
|
313
314
|
case 'version':
|
|
314
315
|
case '--version':
|
package/dist/release.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by .github/workflows/release.yml.
|
|
2
|
-
export const RELEASE_VERSION = "1.2.
|
|
2
|
+
export const RELEASE_VERSION = "1.2.72";
|