@jacebenson/jsn 5.5.5-dev.196.1 → 5.5.5-dev.198.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jacebenson/jsn",
3
- "version": "5.5.5-dev.196.1",
3
+ "version": "5.5.5-dev.198.1",
4
4
  "description": "A command-line interface for ServiceNow that follows the Unix philosophy: simple, composable, and scriptable.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -53,7 +53,7 @@ export function declareCapabilities(name, caps) {
53
53
  /**
54
54
  * The collected capability registry: root command name → capabilities.
55
55
  * Includes the implicit declarations for yargs built-ins ('help') and the
56
- * shell plumbing ('completion') which have no factory to declare from.
56
+ * local commands which have no factory to declare from.
57
57
  *
58
58
  * @returns {Map<string, object>}
59
59
  */
@@ -61,14 +61,13 @@ export function collectCapabilities() {
61
61
  const caps = new Map(REGISTRY);
62
62
  if (!caps.has('help')) caps.set('help', { noInstance: true, skipDailyChecks: true });
63
63
  if (!caps.has('version')) caps.set('version', { noInstance: true, skipDailyChecks: true });
64
- if (!caps.has('completion')) caps.set('completion', { noInstance: true, skipDailyChecks: true });
65
64
  return caps;
66
65
  }
67
66
 
68
67
  /**
69
68
  * Derive the set of root command names that run without an instance.
70
69
  * Preserves the legacy skip-list semantics exactly: help, version,
71
- * completion, setup, auth, skill, docs.
70
+ * setup, auth, skill, docs.
72
71
  *
73
72
  * @param {Map<string, object>} [caps] — from collectCapabilities()
74
73
  * @returns {Set<string>}
@@ -84,7 +83,7 @@ export function noInstanceCommands(caps = collectCapabilities()) {
84
83
  /**
85
84
  * Derive the set of root command names that skip the daily npm-version /
86
85
  * skill checks and the interactive context header. Legacy semantics:
87
- * help, version, completion, skill, docs (a subset of noInstanceCommands).
86
+ * help, version, skill, docs (a subset of noInstanceCommands).
88
87
  *
89
88
  * @param {Map<string, object>} [caps] — from collectCapabilities()
90
89
  * @returns {Set<string>}
@@ -49,7 +49,7 @@ class CommandNode {
49
49
  * subcommand to layer a specialized handler over the base one (see
50
50
  * `requests show`). Appending instead of replacing left the base registration
51
51
  * first in the list and reachable by dispatch/help while the duplicate was
52
- * invisible to the registry (child counts, inventory, completion).
52
+ * invisible to the registry (child counts, inventory).
53
53
  *
54
54
  * Registration order is preserved (the slot is replaced in place) and the
55
55
  * replaced node's aliases are carried over so layered commands keep resolving
@@ -116,7 +116,6 @@ export class LocalCLI {
116
116
  this.middlewares = [];
117
117
  this.failHandler = null;
118
118
  this.script = 'jsn';
119
- this.completionCommand = '__completion';
120
119
  }
121
120
 
122
121
  scriptName(value) { this.script = value; return this; }
@@ -137,7 +136,6 @@ export class LocalCLI {
137
136
  */
138
137
  onParentDiscovery(fn) { this.parentDiscovery = fn; return this; }
139
138
  demandCommand(count, message) { this.root.demand = { count, message }; return this; }
140
- completion(name, _description, handler) { this.completionCommand = name; this.completionHandler = handler; return this; }
141
139
  help() { this.helpEnabled = true; return this; }
142
140
  version() { return this; }
143
141
  strictCommands() { this.strictCmd = true; return this; }
@@ -150,10 +148,6 @@ export class LocalCLI {
150
148
  getCommandHandlers: () => Object.fromEntries(all.map((n) => [n.name, n.definition.handler])),
151
149
  }) };
152
150
  }
153
- showCompletionScript() {
154
- process.stdout.write(`###-begin-jsn-completions-###\n_jsn_yargs_completions() {\n local completions=$(jsn --get-yargs-completions "$@")\n COMPREPLY=( $(compgen -W "$completions" -- "\${COMP_WORDS[COMP_CWORD]}") )\n}\ncomplete -F _jsn_yargs_completions jsn\n###-end-jsn-completions-###\n`);
155
- }
156
-
157
151
  _lookup(list, value) { return list.find((n) => n.name === value || n.aliases.includes(value)); }
158
152
  _knownOptions(nodes) {
159
153
  const map = new Map();
@@ -299,7 +293,7 @@ export class LocalCLI {
299
293
  * stay unchanged.
300
294
  */
301
295
  commandRegistry({ summaries = false } = {}) {
302
- const visible = (node) => node.name !== this.completionCommand && !node.definition.hidden;
296
+ const visible = (node) => !node.definition.hidden;
303
297
  const serialize = (node) => {
304
298
  node.build();
305
299
  const entry = {
@@ -334,7 +328,7 @@ export class LocalCLI {
334
328
  /** Structured child signatures for a parent node, built on demand. */
335
329
  subcommandsOf(node) {
336
330
  return node.children
337
- .filter((child) => child.name !== this.completionCommand && !child.definition.hidden)
331
+ .filter((child) => !child.definition.hidden)
338
332
  .map((child) => {
339
333
  child.build();
340
334
  return {
@@ -362,7 +356,7 @@ export class LocalCLI {
362
356
 
363
357
  _commandRows(node) {
364
358
  return node.children
365
- .filter((child) => child.name !== this.completionCommand && !child.definition.hidden)
359
+ .filter((child) => !child.definition.hidden)
366
360
  .map((child) => ({
367
361
  label: child.definition.command || child.name,
368
362
  description: child.definition.describe || '',
@@ -408,28 +402,10 @@ export class LocalCLI {
408
402
  }));
409
403
  }
410
404
  async parse() {
411
- if (this.args.includes('--get-yargs-completions')) {
412
- const prefix = this.args.at(-1) || '';
413
- let completionArgs = this.args.slice(this.args.indexOf('--get-yargs-completions') + 1, -1);
414
- if (completionArgs[0] === this.script) completionArgs = completionArgs.slice(1);
415
- const { path } = this._findPath(completionArgs);
416
- const node = path.at(-1) || this.root;
417
- node.build();
418
- const argv = { _: path.map((n) => n.name) };
419
- const completionFilter = (callback) => {
420
- const values = [...node.children].filter((n) => n.name !== this.completionCommand && !n.definition.hidden)
421
- .flatMap((n) => path.length ? [n.name] : [n.name, ...n.aliases]);
422
- const opts = [...this._optionConfig(path)].map(([name]) => `--${name}`);
423
- callback(null, [...new Set([...values, ...opts])]);
424
- };
425
- const finish = (values) => process.stdout.write([...new Set(values || [])]
426
- .filter((x) => x.startsWith(prefix) || prefix.startsWith('-') && x.startsWith(prefix)).join('\n') + '\n');
427
- if (this.completionHandler) {
428
- this.completionHandler(prefix, argv, completionFilter, finish);
429
- } else {
430
- completionFilter((err, values) => finish(values));
431
- }
432
- return;
405
+ // Reject stale installed shell snippets instead of dispatching their words
406
+ // as ordinary commands (for example the `r` alias).
407
+ if (this.args.some(arg => arg.split('=')[0] === '--get-yargs-completions')) {
408
+ return this._fail('Unknown option: --get-yargs-completions');
433
409
  }
434
410
  if (this.args[0] === 'help') {
435
411
  const target = this._findPath(this.args.slice(1));
package/src/cli.js CHANGED
@@ -143,9 +143,6 @@ function wrap(handler) {
143
143
  export function buildCLI() {
144
144
  const cfg = loadConfig();
145
145
  const app = new App(cfg);
146
- // Root command names for the completion filter — captured from the yargs
147
- // registry after the chain below finishes registering all commands.
148
- let rootCommands = [];
149
146
 
150
147
  const cliInstance = yargs(hideBin(process.argv))
151
148
  .scriptName('jsn')
@@ -465,64 +462,6 @@ export function buildCLI() {
465
462
  .command(upgradeCmd(wrap))
466
463
  .command(discoverCmd(wrap, (argv) => visibleCommandRegistry(cliInstance.commandRegistry(), app.config, argv)))
467
464
  .demandCommand(1, 'You must specify a command')
468
- // Completion plumbing under a hidden command name, so the explicit
469
- // 'completion' command below owns the UX. (#176)
470
- // The custom filter fixes two yargs behaviors:
471
- // 1. Under strictCommands(), yargs' default completion handler aborts
472
- // when the current word isn't an exact command match. Delegating to
473
- // completionFilter (the default generator) sidesteps that.
474
- // 2. When the current word is an exact ALIAS (e.g. "inc" for incidents),
475
- // yargs descends into that command's subcommands, so a still-being-
476
- // typed "jsn inc<TAB>" offers subcommands that can't match the prefix.
477
- // When completing the FIRST word, merge in the root command list — the
478
- // shell's compgen prefix-filters the final list anyway.
479
- .completion('__completion', false, (current, argv, completionFilter, done) => {
480
- completionFilter((err, completions) => {
481
- let out = completions || [];
482
- const depth = (argv._ || []).length;
483
- if (current && !current.startsWith('-') && depth === 0) {
484
- out = [...new Set([...out, ...rootCommands])];
485
- }
486
- const options = cliInstance.parseGlobalOptions(process.argv.slice(2));
487
- const visible = visibleCommandRegistry(cliInstance.commandRegistry(), loadConfig(options), options);
488
- if (!depth) {
489
- const names = new Set(visible.commands.flatMap(command => [command.name, ...command.aliases]));
490
- out = out.filter(value => value.startsWith('-') || names.has(value));
491
- }
492
- done([...new Set(out)]);
493
- });
494
- })
495
- // User-facing completion command with a real help page (install docs).
496
- // yargs' built-in completion command prints the script even for --help,
497
- // which is why the plumbing above uses the hidden '__completion' name.
498
- .command({
499
- command: 'completion',
500
- describe: 'Generate shell completion script',
501
- builder: (y) => y
502
- .usage('Usage: jsn completion > <file for your shell>')
503
- .epilogue([
504
- 'Install for your shell:',
505
- '',
506
- ' # bash (auto-loaded if the bash-completion package is installed)',
507
- ' jsn completion > ~/.local/share/bash-completion/jsn',
508
- '',
509
- ' # bash (simple)',
510
- ' jsn completion >> ~/.bashrc',
511
- '',
512
- ' # fish',
513
- ' jsn completion > ~/.config/fish/completions/jsn.fish',
514
- '',
515
- ' # zsh — the generated script is bash-style, load via bashcompinit.',
516
- ' # Add to ~/.zshrc:',
517
- ' autoload -U +X bashcompinit && bashcompinit',
518
- ' source <(jsn completion)',
519
- '',
520
- 'Restart your shell (or source the file) after installing.',
521
- ].join('\n')),
522
- handler: () => {
523
- cliInstance.showCompletionScript();
524
- },
525
- })
526
465
  .onParentDiscovery((argv, { path, subcommands }) => {
527
466
  // Reached only for a parent command that declares no default handler of
528
467
  // its own (attachments, docs community, and any future parent) —
@@ -642,10 +581,6 @@ export function buildCLI() {
642
581
  return renderHelp(config, registry, { full: options?.allCommands === true });
643
582
  };
644
583
 
645
- // Snapshot the root command names (plus aliases) for the completion
646
- // filter. Done before any parse — command builders mutate the registry.
647
- rootCommands = cliInstance.getInternalMethods().getCommandInstance().getCommands();
648
-
649
584
  // The capability registry is fully populated now that every command
650
585
  // factory has run — generate the mutation guard's path list.
651
586
  refreshMutationCommands();
@@ -5,7 +5,7 @@ const BASIC_COMMANDS = new Set([
5
5
  'knowledge',
6
6
  'groups', 'groupmembers', 'grouproles', 'users', 'setup', 'auth', 'skill',
7
7
  'cmdb',
8
- 'version', 'upgrade', 'docs', 'history', 'discover', 'completion',
8
+ 'version', 'upgrade', 'docs', 'history', 'discover',
9
9
  'catalogitems', 'cases',
10
10
  ]);
11
11
 
package/src/help.js CHANGED
@@ -158,7 +158,6 @@ const CONFIG_COMMANDS = [
158
158
  { name: 'domains', desc: 'Domains (domain separation)' },
159
159
  { name: 'midservers', desc: 'MID Servers and MID-run commands' },
160
160
  { name: 'platform', desc: 'Platform health and node statistics (read-only)' },
161
- { name: 'completion', desc: 'Shell completion script' },
162
161
  ];
163
162
 
164
163
  const DEVELOPER_COMMANDS = [