@jacebenson/jsn 4.3.13-dev.76.1 → 4.3.13-dev.77.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 +1 -1
- package/src/cli-adapter.js +8 -0
- package/src/cli.js +4 -1
- package/src/commands/_generic.js +7 -0
- package/src/commands/_ticket.js +1 -0
- package/src/commands/discover.js +54 -0
- package/src/help.js +8 -2
package/package.json
CHANGED
package/src/cli-adapter.js
CHANGED
|
@@ -116,6 +116,7 @@ export class LocalCLI {
|
|
|
116
116
|
|
|
117
117
|
scriptName(value) { this.script = value; return this; }
|
|
118
118
|
usage(value) { this.root.usageText = value; return this; }
|
|
119
|
+
epilogue(value) { this.root.epilogueText = value; return this; }
|
|
119
120
|
middleware(fn) { this.middlewares.push(...(Array.isArray(fn) ? fn : [fn])); return this; }
|
|
120
121
|
option(name, config) { this.root.options.set(name, { ...config, name }); return this; }
|
|
121
122
|
options(config) { for (const [name, value] of Object.entries(config)) this.option(name, value); return this; }
|
|
@@ -294,6 +295,13 @@ export class LocalCLI {
|
|
|
294
295
|
aliases: [...node.aliases],
|
|
295
296
|
description: node.definition.describe || '',
|
|
296
297
|
subcommands: node.children.filter(visible).map((child) => child.name),
|
|
298
|
+
discovery: node.definition.discovery || null,
|
|
299
|
+
help: `jsn ${node.name} --help`,
|
|
300
|
+
actions: node.children.filter(visible).map((child) => ({
|
|
301
|
+
name: child.name,
|
|
302
|
+
description: child.definition.describe || '',
|
|
303
|
+
help: `jsn ${node.name} ${child.name} --help`,
|
|
304
|
+
})),
|
|
297
305
|
};
|
|
298
306
|
};
|
|
299
307
|
return {
|
package/src/cli.js
CHANGED
|
@@ -7,7 +7,7 @@ import fs from 'node:fs';
|
|
|
7
7
|
import { loadConfig, globalConfigDir } from './config.js';
|
|
8
8
|
import { App } from './app.js';
|
|
9
9
|
import { resolveSession, applySession } from './session.js';
|
|
10
|
-
import { renderHelp } from './help.js';
|
|
10
|
+
import { renderHelp, renderTips } from './help.js';
|
|
11
11
|
import { isMutationCommand, refreshMutationCommands } from './mutations.js';
|
|
12
12
|
import { skippedUpdatesCmd } from './commands/skipped-updates.js';
|
|
13
13
|
import { noInstanceCommands, dailyCheckSkipCommands, contextHeaderSkipCommands } from './capabilities.js';
|
|
@@ -15,6 +15,7 @@ import { guardExit, exitWithError, AppError, CodeUsage } from './errors.js';
|
|
|
15
15
|
import { formatCommandList } from './helpers.js';
|
|
16
16
|
|
|
17
17
|
// Command modules
|
|
18
|
+
import { discoverCmd } from './commands/discover.js';
|
|
18
19
|
import { setupCmd } from './commands/setup.js';
|
|
19
20
|
import { authCmd } from './commands/auth.js';
|
|
20
21
|
import { recordsCmd } from './commands/records.js';
|
|
@@ -419,6 +420,7 @@ export function buildCLI() {
|
|
|
419
420
|
.command(skillCmd(wrap))
|
|
420
421
|
.command(docsCmd(wrap))
|
|
421
422
|
.command(versionCmd(wrap))
|
|
423
|
+
.command(discoverCmd(wrap, () => cliInstance.commandRegistry()))
|
|
422
424
|
.demandCommand(1, 'You must specify a command')
|
|
423
425
|
// Completion plumbing under a hidden command name, so the explicit
|
|
424
426
|
// 'completion' command below owns the UX. (#176)
|
|
@@ -499,6 +501,7 @@ export function buildCLI() {
|
|
|
499
501
|
}, { summary });
|
|
500
502
|
})(argv);
|
|
501
503
|
})
|
|
504
|
+
.epilogue(renderTips())
|
|
502
505
|
.help('help', 'Show help')
|
|
503
506
|
.version(false)
|
|
504
507
|
.strictCommands()
|
package/src/commands/_generic.js
CHANGED
|
@@ -280,6 +280,13 @@ export function buildDevCmd(name, table, aliases, defaultColumns, wrap, opts = {
|
|
|
280
280
|
command: `${name} [subcommand]`,
|
|
281
281
|
aliases: aliases || [],
|
|
282
282
|
describe: `Manage ${name} (e.g. "${name} list --query nameLIKEincident")`,
|
|
283
|
+
discovery: {
|
|
284
|
+
table,
|
|
285
|
+
defaultColumns,
|
|
286
|
+
benefits: ['Configured list columns', 'Lookup by name or sys_id',
|
|
287
|
+
...(showFields ? ['Configured show fields'] : []),
|
|
288
|
+
...(opts.onShow ? ['Additional table-specific show processing'] : [])],
|
|
289
|
+
},
|
|
283
290
|
builder,
|
|
284
291
|
handler: (_argv) => {
|
|
285
292
|
// This handler only runs when no subcommand is matched (the default case).
|
package/src/commands/_ticket.js
CHANGED
|
@@ -14,6 +14,7 @@ export function buildTicketCommands(table, displayName, alias, defaultColumns, s
|
|
|
14
14
|
command: `${displayName} [subcommand]`,
|
|
15
15
|
aliases: [table, alias],
|
|
16
16
|
describe: `Manage ${displayName} (e.g. "${displayName} list --query priority=1")`,
|
|
17
|
+
discovery: { table, defaultColumns, benefits: ['Configured list columns', 'Ticket-specific create/update flags'] },
|
|
17
18
|
builder: (yargs) => {
|
|
18
19
|
return yargs
|
|
19
20
|
.command({
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { declareCapabilities } from '../capabilities.js';
|
|
2
|
+
|
|
3
|
+
declareCapabilities('discover', { noInstance: true, skipDailyChecks: true });
|
|
4
|
+
|
|
5
|
+
// The live registrations supply names, descriptions, aliases, actions, and
|
|
6
|
+
// factory configuration. No separate inventory of table commands lives here.
|
|
7
|
+
export function discoverCommands(registry, { query = '', table = '' } = {}) {
|
|
8
|
+
const words = query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
9
|
+
return registry.commands.filter(command => {
|
|
10
|
+
const metadata = command.discovery;
|
|
11
|
+
if (table && metadata?.table !== table) return false;
|
|
12
|
+
const haystack = [command.name, ...command.aliases, command.description,
|
|
13
|
+
metadata?.table, ...(metadata?.benefits || []),
|
|
14
|
+
...(command.actions || []).map(action => `${action.name} ${action.description}`)].join(' ').toLowerCase();
|
|
15
|
+
return words.every(word => haystack.includes(word));
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function discoverCmd(wrap, getRegistry) {
|
|
20
|
+
return {
|
|
21
|
+
command: 'discover [query]',
|
|
22
|
+
describe: 'Find commands by words in their names, aliases, descriptions, or configured table',
|
|
23
|
+
builder: y => y
|
|
24
|
+
.positional('query', { type: 'string', describe: 'Search words (quote multiple words)' })
|
|
25
|
+
.option('table', { type: 'string', describe: 'Find specialized commands configured for this exact table' })
|
|
26
|
+
.epilogue([
|
|
27
|
+
'Choose by intent:',
|
|
28
|
+
' Cross-table tasks: jsn records list --table task --query "active=true" --json',
|
|
29
|
+
' Custom tables: jsn records list --table x_example_record --limit 5 --json',
|
|
30
|
+
' Table-specific defaults and views: jsn discover --table incident',
|
|
31
|
+
' Rich request views (attachments and variables): jsn requests show --help',
|
|
32
|
+
' Raw endpoints when needed: jsn rest --help',
|
|
33
|
+
'Generic records supports any accessible table; specialized commands provide configured defaults and table-specific behavior.',
|
|
34
|
+
'Discovery matches registered text; try fewer words if there are no matches.',
|
|
35
|
+
'Use --json for structured results or --json --get data.commands for only matches.',
|
|
36
|
+
].join('\n')),
|
|
37
|
+
handler: wrap(async (argv, app) => {
|
|
38
|
+
const commands = discoverCommands(getRegistry(), { query: argv.query, table: argv.table });
|
|
39
|
+
const lines = commands.flatMap(command => [
|
|
40
|
+
`${command.name}: ${command.description}`,
|
|
41
|
+
...(command.discovery ? [
|
|
42
|
+
` Table: ${command.discovery.table}; default columns: ${command.discovery.defaultColumns.join(', ')}`,
|
|
43
|
+
...command.discovery.benefits.map(benefit => ` ${benefit}`),
|
|
44
|
+
] : []),
|
|
45
|
+
` ${command.help}`,
|
|
46
|
+
...(command.actions || []).map(action => ` ${action.help} — ${action.description}`),
|
|
47
|
+
]);
|
|
48
|
+
if (!commands.length) lines.push('No registered matches. Try fewer words or use generic records for any accessible table: jsn records list --help');
|
|
49
|
+
app.ok({ commands, _formatted: lines.join('\n') }, {
|
|
50
|
+
summary: `${commands.length} matching command(s). Use jsn discover --help for guidance by intent.`,
|
|
51
|
+
});
|
|
52
|
+
}),
|
|
53
|
+
};
|
|
54
|
+
}
|
package/src/help.js
CHANGED
|
@@ -200,14 +200,20 @@ function renderFlags(options) {
|
|
|
200
200
|
return `\nFLAGS\n${lines.join('\n')}`;
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
function renderTips() {
|
|
203
|
+
export function renderTips() {
|
|
204
204
|
return `
|
|
205
205
|
TIPS
|
|
206
|
-
|
|
206
|
+
Find commands by task words: "jsn discover catalog"; by configured table: "jsn discover --table incident"
|
|
207
|
+
Cross-table task searches and custom tables: "jsn records list --help"
|
|
208
|
+
Specialized commands offer configured columns, lookup, and table-specific views; inspect discovery results for details
|
|
209
|
+
Raw endpoints when needed: "jsn rest --help"; examples and intent guidance: "jsn discover --help"
|
|
207
210
|
Use "jsn <command> --help" for details, or "jsn <command> list --help" for list options
|
|
208
211
|
"jsn --json" prints the registered command surface as JSON for scripts and agents
|
|
209
212
|
|
|
210
213
|
LEARN MORE
|
|
214
|
+
Some list commands offer a picker in an interactive terminal with automatic output.
|
|
215
|
+
Arrow keys browse (10 visible items); type to search; scroll to load more; Enter selects; Esc cancels.
|
|
216
|
+
Picker eligibility and search fields vary by command. Explicit output formats (including --json) skip pickers.
|
|
211
217
|
Use "jsn <command> --help" for more information about a command.`;
|
|
212
218
|
}
|
|
213
219
|
|