@jacebenson/jsn 5.5.1-dev.169.1 → 5.5.1-dev.171.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 +1 -1
- package/package.json +1 -1
- package/src/cli-adapter.js +8 -2
- package/src/cli.js +8 -2
- package/src/commands/_generic.js +10 -2
- package/src/commands/_ticket.js +10 -2
- package/src/commands/approvals.js +1 -0
- package/src/commands/discover.js +1 -0
- package/src/commands/knowledge.js +1 -0
- package/src/commands/records.js +11 -2
- package/src/commands/setup.js +1 -0
- package/src/commands/tickets.js +10 -2
- package/src/help.js +93 -20
- package/src/helpers.js +16 -0
- package/src/output.js +6 -0
- package/src/record-command-profiles.js +8 -4
- package/src/record-profiles.js +1 -0
package/README.md
CHANGED
|
@@ -121,7 +121,7 @@ jsn records list --table incident --limit 10 --json
|
|
|
121
121
|
jsn flows list
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
-
Run `jsn --help` for the command
|
|
124
|
+
Run `jsn --help` for a concise command overview, or `jsn --all-commands --help` for the complete command and flag reference. See the [CLI guide](https://github.com/jacebenson/jsn/blob/main/docs/cli-guide.md) for authentication, output formats, development, and examples. The [docs site](https://jacebenson.github.io/jsn/) has feature guides.
|
|
125
125
|
|
|
126
126
|
## AI agents
|
|
127
127
|
|
package/package.json
CHANGED
package/src/cli-adapter.js
CHANGED
|
@@ -293,12 +293,16 @@ export class LocalCLI {
|
|
|
293
293
|
* discovery output are generated from, so neither can drift away from the
|
|
294
294
|
* commands that actually exist. Builders run here (idempotently) because a
|
|
295
295
|
* parent's children are only registered when its builder is invoked.
|
|
296
|
+
*
|
|
297
|
+
* `summaries: true` adds the command's short summary for the concise human
|
|
298
|
+
* help page. Machine discovery leaves it out, so the JSON schema and bytes
|
|
299
|
+
* stay unchanged.
|
|
296
300
|
*/
|
|
297
|
-
commandRegistry() {
|
|
301
|
+
commandRegistry({ summaries = false } = {}) {
|
|
298
302
|
const visible = (node) => node.name !== this.completionCommand && !node.definition.hidden;
|
|
299
303
|
const serialize = (node) => {
|
|
300
304
|
node.build();
|
|
301
|
-
|
|
305
|
+
const entry = {
|
|
302
306
|
name: node.name,
|
|
303
307
|
command: node.definition.command || node.name,
|
|
304
308
|
aliases: [...node.aliases],
|
|
@@ -312,6 +316,8 @@ export class LocalCLI {
|
|
|
312
316
|
help: `jsn ${node.name} ${child.name} --help`,
|
|
313
317
|
})),
|
|
314
318
|
};
|
|
319
|
+
if (summaries) entry.summary = node.definition.summary || '';
|
|
320
|
+
return entry;
|
|
315
321
|
};
|
|
316
322
|
return {
|
|
317
323
|
commands: this.root.children.filter(visible).map(serialize),
|
package/src/cli.js
CHANGED
|
@@ -605,7 +605,11 @@ export function buildCLI() {
|
|
|
605
605
|
// non-interactive discovery retain their existing reference output.
|
|
606
606
|
const config = loadConfig(formatArgv);
|
|
607
607
|
const welcome = maybeShowHome({ argv: formatArgv, requestedFormat, cfg: config });
|
|
608
|
-
if (!welcome)
|
|
608
|
+
if (!welcome) {
|
|
609
|
+
const registry = visibleCommandRegistry(
|
|
610
|
+
cliInstance.commandRegistry({ summaries: true }), config, formatArgv);
|
|
611
|
+
process.stdout.write(renderHelp(config, registry, { full: formatArgv?.allCommands === true }) + '\n');
|
|
612
|
+
}
|
|
609
613
|
process.exit(0);
|
|
610
614
|
}
|
|
611
615
|
// Every other failure here (unknown command, missing required argument,
|
|
@@ -628,7 +632,9 @@ export function buildCLI() {
|
|
|
628
632
|
cliInstance.rootHelpRenderer = () => {
|
|
629
633
|
const options = cliInstance.parseGlobalOptions(process.argv.slice(2));
|
|
630
634
|
const config = loadConfig(options);
|
|
631
|
-
|
|
635
|
+
const registry = visibleCommandRegistry(
|
|
636
|
+
cliInstance.commandRegistry({ summaries: true }), config, options);
|
|
637
|
+
return renderHelp(config, registry, { full: options?.allCommands === true });
|
|
632
638
|
};
|
|
633
639
|
|
|
634
640
|
// Snapshot the root command names (plus aliases) for the completion
|
package/src/commands/_generic.js
CHANGED
|
@@ -2,7 +2,7 @@ import { constrainQuery, constrainedQueryHelp } from '../constrained-query.js';
|
|
|
2
2
|
import { enrichRelatedLists, relatedListOptions } from '../related-lists.js';
|
|
3
3
|
// Generic table-based CRUD command builder
|
|
4
4
|
|
|
5
|
-
import { formatRecordForDisplay, getStringField, buildRecordPayload, confirmDelete, interactiveList, canPrompt } from '../helpers.js';
|
|
5
|
+
import { formatRecordForDisplay, findOmittedColumns, getStringField, buildRecordPayload, confirmDelete, interactiveList, canPrompt } from '../helpers.js';
|
|
6
6
|
import { getRecord, listRecords, recordListParams, createRecord, updateRecord, deleteRecord, recordOptions } from '../records-engine.js';
|
|
7
7
|
import { unwrapSysId } from '../resolve-record.js';
|
|
8
8
|
import { getCurrentUser, getCurrentApplication } from '../context.js';
|
|
@@ -171,11 +171,19 @@ export function buildDevCmd(name, table, aliases, defaultColumns, wrap, opts = {
|
|
|
171
171
|
const q = `${constrainedQuery}${constrainedQuery ? '^' : ''}ORDERBYDESCsys_updated_on`;
|
|
172
172
|
const params = recordListParams({ limit, fields: ['sys_id', ...columns], query: q });
|
|
173
173
|
const records = await listRecords(app.sdk, { table, params, displayValues: argv.displayValues ?? opts.referenceMode });
|
|
174
|
+
const missingColumns = findOmittedColumns(records, columns);
|
|
175
|
+
const presentColumns = missingColumns.length ? columns.filter(c => !missingColumns.includes(c)) : columns;
|
|
174
176
|
app.ok({
|
|
175
177
|
table,
|
|
176
178
|
count: records.length,
|
|
177
179
|
columns,
|
|
178
|
-
|
|
180
|
+
...(missingColumns.length ? {
|
|
181
|
+
missing_columns: missingColumns,
|
|
182
|
+
warnings: [
|
|
183
|
+
`Column(s) not returned by ServiceNow (non-existent or restricted on ${table}): ${missingColumns.join(', ')}. Run \`jsn columns --table ${table}\` to inspect valid fields.`,
|
|
184
|
+
],
|
|
185
|
+
} : {}),
|
|
186
|
+
records: argv.displayValues || opts.listProjection === 'full' ? records : records.map(r => formatRecordForDisplay(r, presentColumns)),
|
|
179
187
|
context: { instance_url: app.getEffectiveInstance() },
|
|
180
188
|
}, {
|
|
181
189
|
summary: `${records.length} ${name}(s)`,
|
package/src/commands/_ticket.js
CHANGED
|
@@ -2,7 +2,7 @@ import { enrichRelatedLists, relatedListOptions } from '../related-lists.js';
|
|
|
2
2
|
// Generic command builder for CRUD operations on a ServiceNow table
|
|
3
3
|
// Used by incidents, changes, requests, tasks, and most dev subcommands
|
|
4
4
|
|
|
5
|
-
import { getStringField, formatRecordForDisplay, buildQuerySuffix, resolveFieldsParam, confirmDelete, interactiveList, canPrompt, buildRecordPayload } from '../helpers.js';
|
|
5
|
+
import { getStringField, formatRecordForDisplay, findOmittedColumns, buildQuerySuffix, resolveFieldsParam, confirmDelete, interactiveList, canPrompt, buildRecordPayload } from '../helpers.js';
|
|
6
6
|
import { getRecord, listRecords, recordListParams, createRecord, updateRecord, deleteRecord, recordOptions } from '../records-engine.js';
|
|
7
7
|
import { resolveSysId } from '../resolve-record.js';
|
|
8
8
|
import { FormatAuto } from '../output.js';
|
|
@@ -88,7 +88,9 @@ export function buildTicketCommands(table, displayName, alias, defaultColumns, s
|
|
|
88
88
|
const params = recordListParams({ limit, offset, fields, query: q });
|
|
89
89
|
|
|
90
90
|
const records = await listRecords(app.sdk, { table, params, displayValues: argv.displayValues ?? opts.referenceMode });
|
|
91
|
-
const
|
|
91
|
+
const missingColumns = fields ? findOmittedColumns(records, columns) : [];
|
|
92
|
+
const presentColumns = missingColumns.length ? columns.filter(c => !missingColumns.includes(c)) : columns;
|
|
93
|
+
const displayRecords = fields && !argv.displayValues && opts.listProjection !== 'full' ? records.map(r => formatRecordForDisplay(r, presentColumns)) : records;
|
|
92
94
|
|
|
93
95
|
const breadcrumbs = [
|
|
94
96
|
{ action: 'create', cmd: `jsn ${alias} create --description "..."`, description: `Create a new ${displayName}` },
|
|
@@ -114,6 +116,12 @@ export function buildTicketCommands(table, displayName, alias, defaultColumns, s
|
|
|
114
116
|
table,
|
|
115
117
|
count: records.length,
|
|
116
118
|
columns,
|
|
119
|
+
...(missingColumns.length ? {
|
|
120
|
+
missing_columns: missingColumns,
|
|
121
|
+
warnings: [
|
|
122
|
+
`Column(s) not returned by ServiceNow (non-existent or restricted on ${table}): ${missingColumns.join(', ')}. Run \`jsn columns --table ${table}\` to inspect valid fields.`,
|
|
123
|
+
],
|
|
124
|
+
} : {}),
|
|
117
125
|
records: displayRecords,
|
|
118
126
|
pagination: { limit, offset, hasMore: records.length === limit },
|
|
119
127
|
context: { instance_url: app.getEffectiveInstance() },
|
|
@@ -173,6 +173,7 @@ export function approvalsCmd(wrap) {
|
|
|
173
173
|
return {
|
|
174
174
|
command: 'approvals [subcommand]',
|
|
175
175
|
describe: 'Manage approval requests (list, approve, reject, submit, history)',
|
|
176
|
+
summary: 'List, approve, or reject approval requests',
|
|
176
177
|
builder: (yargs) => {
|
|
177
178
|
return yargs
|
|
178
179
|
.command({
|
package/src/commands/discover.js
CHANGED
|
@@ -20,6 +20,7 @@ export function discoverCmd(wrap, getRegistry) {
|
|
|
20
20
|
return {
|
|
21
21
|
command: 'discover [query]',
|
|
22
22
|
describe: 'Find commands by words in their names, aliases, descriptions, or configured table',
|
|
23
|
+
summary: 'Find commands by task word or table',
|
|
23
24
|
builder: y => y
|
|
24
25
|
.positional('query', { type: 'string', describe: 'Search words (quote multiple words)' })
|
|
25
26
|
.option('table', { type: 'string', describe: 'Find specialized commands configured for this exact table' })
|
|
@@ -26,6 +26,7 @@ export function knowledgeCmd(wrap) {
|
|
|
26
26
|
return {
|
|
27
27
|
command: 'knowledge [subcommand]', aliases: ['kb'],
|
|
28
28
|
describe: 'Search and read knowledge articles through the Knowledge API',
|
|
29
|
+
summary: 'Search and read knowledge articles',
|
|
29
30
|
handler: wrap(async (argv, app) => emit(app, argv,
|
|
30
31
|
{ subcommands: argv.subcommands || [], _formatted: formatCommandList({ title: 'Knowledge articles', commands: argv.subcommands || [] }) },
|
|
31
32
|
'Search and read knowledge articles', [{ action: 'search', cmd: 'jsn knowledge search <text>', description: 'Find accessible articles' }])),
|
package/src/commands/records.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { formatCommandList, formatRecordForDisplay, buildQuerySuffix, buildRecordPayload, getStringField, interactiveList, resolveFieldsParam, checkDerivedFields, confirmDelete, verifyWriteBack } from '../helpers.js';
|
|
1
|
+
import { formatCommandList, formatRecordForDisplay, findOmittedColumns, buildQuerySuffix, buildRecordPayload, getStringField, interactiveList, resolveFieldsParam, checkDerivedFields, confirmDelete, verifyWriteBack } from '../helpers.js';
|
|
2
2
|
import { listRecords, recordListParams, getRecord, createRecord, updateRecord, deleteRecord } from '../records-engine.js';
|
|
3
3
|
import { resolveRecord, unwrapSysId } from '../resolve-record.js';
|
|
4
4
|
import { errUsage } from '../errors.js';
|
|
@@ -83,6 +83,7 @@ export function recordsCmd(wrap) {
|
|
|
83
83
|
return {
|
|
84
84
|
command: 'records [subcommand]',
|
|
85
85
|
describe: 'Query and manage records in any table (e.g. "records list --table incident --query priority=1")',
|
|
86
|
+
summary: 'Query any table when no specialized command fits',
|
|
86
87
|
builder: (yargs) => {
|
|
87
88
|
return yargs
|
|
88
89
|
.command({
|
|
@@ -149,7 +150,9 @@ export function recordsCmd(wrap) {
|
|
|
149
150
|
const fields = resolveFieldsParam(columns);
|
|
150
151
|
const params = recordListParams({ limit: argv['sys-id'] ? 1 : argv.limit, offset: argv.offset, fields, query });
|
|
151
152
|
const records = await listRecords(app.sdk, { table, params, displayValues: argv.displayValues });
|
|
152
|
-
const
|
|
153
|
+
const missingColumns = fields ? findOmittedColumns(records, columns) : [];
|
|
154
|
+
const presentColumns = missingColumns.length ? columns.filter(c => !missingColumns.includes(c)) : columns;
|
|
155
|
+
const displayRecords = fields && !argv.displayValues ? records.map(r => formatRecordForDisplay(r, presentColumns)) : records;
|
|
153
156
|
|
|
154
157
|
// include_counts: default opt-in on every list. Opt out per-profile
|
|
155
158
|
// (config include_counts:false) or per-invocation (--no-count).
|
|
@@ -190,6 +193,12 @@ export function recordsCmd(wrap) {
|
|
|
190
193
|
table,
|
|
191
194
|
count: records.length,
|
|
192
195
|
columns,
|
|
196
|
+
...(missingColumns.length ? {
|
|
197
|
+
missing_columns: missingColumns,
|
|
198
|
+
warnings: [
|
|
199
|
+
`Column(s) not returned by ServiceNow (non-existent or restricted on ${table}): ${missingColumns.join(', ')}. Run \`jsn columns --table ${table}\` to inspect valid fields.`,
|
|
200
|
+
],
|
|
201
|
+
} : {}),
|
|
193
202
|
records: displayRecords,
|
|
194
203
|
pagination: { limit: argv.limit, offset: argv.offset, ...(total != null ? { total, hasMore: argv.offset + argv.limit < total } : {}) },
|
|
195
204
|
context: { instance_url: app.getEffectiveInstance() },
|
package/src/commands/setup.js
CHANGED
|
@@ -121,6 +121,7 @@ export function setupCmd(wrap) {
|
|
|
121
121
|
return {
|
|
122
122
|
command: 'setup',
|
|
123
123
|
describe: 'Set up JSN defaults and manage ServiceNow connections (interactive)',
|
|
124
|
+
summary: 'Connect to ServiceNow and manage profiles',
|
|
124
125
|
builder: y => y.option('docs-source', { type: 'string', choices: ['snapshot', 'github', 'skip'], describe: 'Install optional documentation directly without the authentication wizard' })
|
|
125
126
|
.option('configure-defaults', { type: 'boolean', describe: 'Configure defaults for future connections without the hub' })
|
|
126
127
|
.option('configure-docs', { type: 'boolean', describe: 'Configure documentation without the hub' }).epilogue(setupHelp()),
|
package/src/commands/tickets.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { enrichRelatedLists, relatedListOptions } from '../related-lists.js';
|
|
2
|
-
import { formatRecordForDisplay, getStringField, buildQuerySuffix, resolveFieldsParam, buildRecordPayload, confirmDelete } from '../helpers.js';
|
|
2
|
+
import { formatRecordForDisplay, findOmittedColumns, getStringField, buildQuerySuffix, resolveFieldsParam, buildRecordPayload, confirmDelete } from '../helpers.js';
|
|
3
3
|
import { getRecord, listRecords, recordListParams, createRecord, updateRecord, deleteRecord, recordOptions } from '../records-engine.js';
|
|
4
4
|
import { resolveSysId } from '../resolve-record.js';
|
|
5
5
|
import { declareCapabilities } from '../capabilities.js';
|
|
@@ -28,7 +28,9 @@ export function ticketsCmd(wrap) {
|
|
|
28
28
|
const q = argv.query ? argv.query + '^ORDERBYDESCsys_updated_on' : 'ORDERBYDESCsys_updated_on';
|
|
29
29
|
const params = recordListParams({ limit: argv.limit, offset: argv.offset, fields, query: q });
|
|
30
30
|
const records = await listRecords(app.sdk, { table: 'task', params, displayValues: argv.displayValues });
|
|
31
|
-
const
|
|
31
|
+
const missingColumns = fields ? findOmittedColumns(records, columns) : [];
|
|
32
|
+
const presentColumns = missingColumns.length ? columns.filter(c => !missingColumns.includes(c)) : columns;
|
|
33
|
+
const displayRecords = fields && !argv.displayValues ? records.map(r => formatRecordForDisplay(r, presentColumns)) : records;
|
|
32
34
|
const breadcrumbs = [
|
|
33
35
|
{ action: 'create', cmd: 'jsn tickets create -f short_description=New ticket', description: 'Create a new ticket' },
|
|
34
36
|
];
|
|
@@ -50,6 +52,12 @@ export function ticketsCmd(wrap) {
|
|
|
50
52
|
table: 'task',
|
|
51
53
|
count: records.length,
|
|
52
54
|
columns,
|
|
55
|
+
...(missingColumns.length ? {
|
|
56
|
+
missing_columns: missingColumns,
|
|
57
|
+
warnings: [
|
|
58
|
+
`Column(s) not returned by ServiceNow (non-existent or restricted on task): ${missingColumns.join(', ')}. Run \`jsn columns --table task\` to inspect valid fields.`,
|
|
59
|
+
],
|
|
60
|
+
} : {}),
|
|
53
61
|
records: displayRecords,
|
|
54
62
|
pagination: { limit: argv.limit, offset: argv.offset, hasMore: records.length === argv.limit },
|
|
55
63
|
context: { instance_url: app.getEffectiveInstance() },
|
package/src/help.js
CHANGED
|
@@ -10,20 +10,49 @@
|
|
|
10
10
|
// (`approvals`, `cmdb`, `docs`, `perf`, `platform`, … were missing from the
|
|
11
11
|
// hand-written list while being fully registered).
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
const COMMON_COMMANDS = [
|
|
14
|
+
'incidents', 'requests', 'tasks', 'changes', 'approvals', 'knowledge', 'records', 'setup', 'discover',
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
const CONCISE_FLAGS = ['instance', 'profile', 'json'];
|
|
18
|
+
|
|
19
|
+
const CONCISE_EXAMPLES = [
|
|
20
|
+
'jsn incidents list --query "active=true" --limit 5',
|
|
21
|
+
'jsn records list --table incident --limit 5 --json',
|
|
22
|
+
'jsn discover catalog',
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const CONCISE_MORE = [
|
|
26
|
+
{ label: 'jsn <command> <action> --help', description: 'Options for one command or action' },
|
|
27
|
+
{ label: 'jsn discover <word>', description: 'Find commands by task words' },
|
|
28
|
+
{ label: 'jsn discover --table <table>', description: 'Find commands configured for a table' },
|
|
29
|
+
{ label: 'jsn --all-commands --help', description: 'Every registered command and global flag' },
|
|
30
|
+
{ label: 'jsn --json', description: 'Registered command surface as JSON' },
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
function renderGroup(name, commands, width = helpWidth()) {
|
|
14
34
|
const lines = [`\n${name}`];
|
|
15
35
|
lines.push('─'.repeat(50));
|
|
36
|
+
let rows = [];
|
|
37
|
+
const flush = () => {
|
|
38
|
+
if (!rows.length) return;
|
|
39
|
+
lines.push(renderRows(rows, { width, indent: 2 }));
|
|
40
|
+
rows = [];
|
|
41
|
+
};
|
|
16
42
|
for (const cmd of commands) {
|
|
17
43
|
if (cmd.divider) {
|
|
44
|
+
flush();
|
|
18
45
|
lines.push('');
|
|
19
46
|
lines.push(` ${cmd.divider}`);
|
|
20
47
|
continue;
|
|
21
48
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
49
|
+
rows.push({
|
|
50
|
+
label: cmd.name,
|
|
51
|
+
description: cmd.desc,
|
|
52
|
+
note: cmd.alias ? `(${cmd.alias})` : '',
|
|
53
|
+
});
|
|
26
54
|
}
|
|
55
|
+
flush();
|
|
27
56
|
return lines.join('\n');
|
|
28
57
|
}
|
|
29
58
|
|
|
@@ -186,21 +215,57 @@ function rowsFor(hint, byName, used, config) {
|
|
|
186
215
|
return rows;
|
|
187
216
|
}
|
|
188
217
|
|
|
189
|
-
function renderFlags(options) {
|
|
218
|
+
function renderFlags(options, { full = false, width = helpWidth() } = {}) {
|
|
190
219
|
// Derived from the registered global options, so a new global flag cannot be
|
|
191
|
-
// missing from
|
|
192
|
-
|
|
193
|
-
|
|
220
|
+
// missing from the full reference (--get and --csv were, along with the csv
|
|
221
|
+
// format choice). The concise page shows only the flags needed to point a
|
|
222
|
+
// command at an instance and choose machine output.
|
|
223
|
+
const rows = [];
|
|
224
|
+
const specs = full
|
|
225
|
+
? options
|
|
226
|
+
: CONCISE_FLAGS.map((name) => options.find((spec) => spec.name === name)).filter(Boolean);
|
|
227
|
+
for (const spec of specs) {
|
|
194
228
|
if (spec.name === 'help') continue;
|
|
195
229
|
const alias = spec.alias.map(name => `${name.length === 1 ? '-' : '--'}${name}`).join(', ');
|
|
196
230
|
const label = `${alias ? `${alias}, ` : ''}--${spec.name}`;
|
|
197
231
|
const suffix = spec.name === 'format' && spec.choices.length
|
|
198
|
-
? `
|
|
199
|
-
: `
|
|
200
|
-
|
|
232
|
+
? `[string: ${spec.choices.join(', ')}]`
|
|
233
|
+
: `[${spec.type}]`;
|
|
234
|
+
rows.push({ label, description: spec.description, note: suffix });
|
|
201
235
|
}
|
|
202
|
-
|
|
203
|
-
return `\nFLAGS\n${
|
|
236
|
+
rows.push({ label: '--help', description: 'Show help', note: '[boolean]' });
|
|
237
|
+
return `\nFLAGS\n${renderRows(rows, { width, indent: 2 })}`;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* The ordinary root page: common task commands, a few flags, runnable
|
|
242
|
+
* examples, and pointers to the exhaustive reference and local discovery.
|
|
243
|
+
*/
|
|
244
|
+
function renderConciseHelp(config, registry, width) {
|
|
245
|
+
const commands = Array.isArray(registry?.commands) ? registry.commands : [];
|
|
246
|
+
const byName = new Map(commands.map((command) => [command.name, command]));
|
|
247
|
+
const common = COMMON_COMMANDS
|
|
248
|
+
.map((name) => byName.get(name))
|
|
249
|
+
.filter((command) => command && !isCapabilityHidden(command.name, config))
|
|
250
|
+
.map((command) => ({
|
|
251
|
+
name: command.name,
|
|
252
|
+
desc: command.summary || command.description || '',
|
|
253
|
+
}));
|
|
254
|
+
|
|
255
|
+
return [
|
|
256
|
+
'Usage: jsn <command> [options]',
|
|
257
|
+
'',
|
|
258
|
+
'Command-line interface for ServiceNow',
|
|
259
|
+
renderGroup('COMMON COMMANDS', common, width),
|
|
260
|
+
'',
|
|
261
|
+
'EXAMPLES',
|
|
262
|
+
...CONCISE_EXAMPLES.map((example) => ` ${example}`),
|
|
263
|
+
renderFlags(Array.isArray(registry?.options) ? registry.options : [], { width }),
|
|
264
|
+
'',
|
|
265
|
+
'MORE',
|
|
266
|
+
renderRows(CONCISE_MORE, { width, indent: 2 }),
|
|
267
|
+
'',
|
|
268
|
+
].join('\n');
|
|
204
269
|
}
|
|
205
270
|
|
|
206
271
|
export function renderTips() {
|
|
@@ -212,7 +277,7 @@ TIPS
|
|
|
212
277
|
Cross-table task searches and custom tables: "jsn records list --help"
|
|
213
278
|
Specialized commands offer configured columns, lookup, and table-specific views; inspect discovery results for details
|
|
214
279
|
Raw endpoints when needed: "jsn rest --help"; examples and intent guidance: "jsn discover --help"
|
|
215
|
-
Use "jsn <command> --help" for
|
|
280
|
+
Use "jsn <command> <action> --help" for options on one command or action
|
|
216
281
|
"jsn --json" prints the registered command surface as JSON for scripts and agents
|
|
217
282
|
|
|
218
283
|
LEARN MORE
|
|
@@ -223,14 +288,22 @@ LEARN MORE
|
|
|
223
288
|
}
|
|
224
289
|
|
|
225
290
|
/**
|
|
226
|
-
* Render
|
|
291
|
+
* Render root help.
|
|
292
|
+
*
|
|
293
|
+
* The ordinary page is a concise task directory. `full: true` (used by
|
|
294
|
+
* `--all-commands --help`) renders the exhaustive grouped reference: every
|
|
295
|
+
* visible registered command and every registered global option, plus the
|
|
296
|
+
* tips and picker details that would crowd the short page.
|
|
227
297
|
*
|
|
228
298
|
* @param {object} config — profile config (capability-conditioned hiding)
|
|
229
299
|
* @param {{commands: Array, options: Array}} [registry] — from
|
|
230
300
|
* `cli.commandRegistry()`. Without it only the hint tables render, which is
|
|
231
301
|
* the fallback for callers that have no registry (unit tests).
|
|
302
|
+
* @param {{full?: boolean, width?: number}} [opts]
|
|
232
303
|
*/
|
|
233
|
-
export function renderHelp(config, registry = null) {
|
|
304
|
+
export function renderHelp(config, registry = null, { full = false, width = helpWidth() } = {}) {
|
|
305
|
+
if (!full) return renderConciseHelp(config, registry, width);
|
|
306
|
+
|
|
234
307
|
const commands = Array.isArray(registry?.commands) ? registry.commands : [];
|
|
235
308
|
const byName = new Map(commands.map((command) => [command.name, command]));
|
|
236
309
|
const used = new Set();
|
|
@@ -238,14 +311,14 @@ export function renderHelp(config, registry = null) {
|
|
|
238
311
|
const sections = Object.entries(COMMAND_GROUPS)
|
|
239
312
|
.map(([name, hint]) => [name, rowsFor(hint, byName, used, config)])
|
|
240
313
|
.filter(([, rows]) => rows.some((row) => !row.divider))
|
|
241
|
-
.map(([name, rows]) => renderGroup(name, rows));
|
|
314
|
+
.map(([name, rows]) => renderGroup(name, rows, width));
|
|
242
315
|
|
|
243
316
|
// Anything registered that the hint tables don't place. This is the safety
|
|
244
317
|
// net that keeps help complete as commands are added at the root.
|
|
245
318
|
const unplaced = commands
|
|
246
319
|
.filter((command) => !used.has(command.name) && !isCapabilityHidden(command.name, config))
|
|
247
320
|
.map((command) => ({ name: command.name, alias: command.aliases[0] || '', desc: command.description || '' }));
|
|
248
|
-
if (unplaced.length) sections.push(renderGroup('MORE', unplaced));
|
|
321
|
+
if (unplaced.length) sections.push(renderGroup('MORE', unplaced, width));
|
|
249
322
|
|
|
250
323
|
return [
|
|
251
324
|
'Usage: jsn <command> [options]',
|
|
@@ -254,7 +327,7 @@ export function renderHelp(config, registry = null) {
|
|
|
254
327
|
'',
|
|
255
328
|
...sections,
|
|
256
329
|
'',
|
|
257
|
-
renderFlags(Array.isArray(registry?.options) ? registry.options : []),
|
|
330
|
+
renderFlags(Array.isArray(registry?.options) ? registry.options : [], { full: true, width }),
|
|
258
331
|
renderTips(),
|
|
259
332
|
'',
|
|
260
333
|
].join('\n');
|
package/src/helpers.js
CHANGED
|
@@ -298,6 +298,22 @@ export function formatRecordForDisplay(record, columns) {
|
|
|
298
298
|
return result;
|
|
299
299
|
}
|
|
300
300
|
|
|
301
|
+
/**
|
|
302
|
+
* Identify requested columns that ServiceNow omitted from every returned row
|
|
303
|
+
* (because the field does not exist on the table or is blocked by ACLs).
|
|
304
|
+
* An existing empty column is still present as a key (`col in row === true`).
|
|
305
|
+
*
|
|
306
|
+
* @param {Array<object>} records — raw records from ServiceNow Table API
|
|
307
|
+
* @param {string[]} columns — requested column names
|
|
308
|
+
* @returns {string[]} columns absent from all returned records
|
|
309
|
+
*/
|
|
310
|
+
export function findOmittedColumns(records, columns) {
|
|
311
|
+
if (!Array.isArray(records) || records.length === 0 || !Array.isArray(columns) || columns.includes('*')) {
|
|
312
|
+
return [];
|
|
313
|
+
}
|
|
314
|
+
return columns.filter(col => col && col !== '*' && !records.some(r => r && typeof r === 'object' && col in r));
|
|
315
|
+
}
|
|
316
|
+
|
|
301
317
|
export function truncateString(str, maxLen) {
|
|
302
318
|
if (!str || str.length <= maxLen) return str;
|
|
303
319
|
return str.slice(0, maxLen - 3) + '...';
|
package/src/output.js
CHANGED
|
@@ -364,6 +364,12 @@ export class OutputWriter {
|
|
|
364
364
|
this.writeFormattedRecord(data, tableName);
|
|
365
365
|
}
|
|
366
366
|
|
|
367
|
+
if (Array.isArray(data.warnings) && data.warnings.length > 0 && !data._formatted) {
|
|
368
|
+
for (const w of data.warnings) {
|
|
369
|
+
this.writer.write(colorYellow(`⚠ ${w}\n`));
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
367
373
|
if (Array.isArray(data.records) && data.records.length > 0) {
|
|
368
374
|
// A _formatted visual (e.g. cmdb relationship tree) replaces the
|
|
369
375
|
// flat table in styled mode — showing both is noise.
|
|
@@ -59,10 +59,14 @@ export default {
|
|
|
59
59
|
options: { singular: 'catalog UI policy', scopeValidation: true } },
|
|
60
60
|
tables: { table: 'sys_db_object', aliases: ['table', 't'], columns: ['name', 'label', 'super_class', 'create_access_controls'],
|
|
61
61
|
options: { singular: 'table', scopeValidation: true, showFields: ['name', 'label', 'super_class', 'create_access_controls', 'sys_scope', 'sys_created_on', 'sys_updated_on', 'sys_created_by', 'sys_updated_by', 'is_extendable'] } },
|
|
62
|
-
incidents: { table: 'incident', aliases: ['incident', 'inc'], columns: ['number', 'short_description', 'priority', 'state', 'assigned_to'], kind: 'ticket'
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
incidents: { table: 'incident', aliases: ['incident', 'inc'], columns: ['number', 'short_description', 'priority', 'state', 'assigned_to'], kind: 'ticket',
|
|
63
|
+
summary: 'List, show, create, or update incidents' },
|
|
64
|
+
changes: { table: 'change_request', aliases: ['change_request', 'chg'], columns: ['number', 'short_description', 'risk', 'state', 'assigned_to'], kind: 'ticket',
|
|
65
|
+
summary: 'Work with change requests' },
|
|
66
|
+
requests: { table: 'sc_req_item', aliases: ['sc_req_item', 'req'], columns: ['number', 'cat_item', 'short_description', 'stage', 'assigned_to'], kind: 'ticket',
|
|
67
|
+
summary: 'Work with requested items' },
|
|
68
|
+
tasks: { table: 'sc_task', aliases: ['sc_task', 'task'], columns: ['number', 'short_description', 'state', 'assigned_to'], kind: 'ticket',
|
|
69
|
+
summary: 'Work with catalog tasks' },
|
|
66
70
|
uipolicies: { table: 'sys_ui_policy', aliases: ['uipolicy', 'up'], columns: ['short_description', 'table', 'sys_class_name', 'active'],
|
|
67
71
|
identifierField: 'short_description', options: { singular: 'UI policy', scopeValidation: true },
|
|
68
72
|
relationships: { essential: [{ name: 'actions', table: 'sys_ui_policy_action', foreignKey: 'ui_policy', limit: 100, orderBy: 'order',
|
package/src/record-profiles.js
CHANGED
|
@@ -83,6 +83,7 @@ export function buildRecordProfile(definition, wrap, hooks = {}) {
|
|
|
83
83
|
? buildTicketCommands(profile.table, profile.name, profile.aliases.find(alias => alias !== profile.table), profile.columns, {}, null, wrap, options)
|
|
84
84
|
: buildDevCmd(profile.name, profile.table, profile.aliases, profile.columns, wrap, options);
|
|
85
85
|
command.aliases = [...profile.aliases];
|
|
86
|
+
command.summary = profile.summary || '';
|
|
86
87
|
command.recordProfile = profile;
|
|
87
88
|
command.discovery.benefits.push(
|
|
88
89
|
`Reference output: ${profile.output.references}; list projection: ${profile.output.listProjection}`,
|