@jacebenson/jsn 4.3.7-dev.28 → 4.3.7-dev.29

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": "4.3.7-dev.28",
3
+ "version": "4.3.7-dev.29",
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": {
@@ -397,22 +397,48 @@ export function midserversCmd(wrap) {
397
397
  }),
398
398
  })
399
399
  .command({
400
- command: 'execute <identifier>',
400
+ command: 'execute [identifier]',
401
401
  describe: 'Execute a shell command through a MID Server',
402
402
  builder: (b) => b
403
- .option('command', { alias: 'c', type: 'string', demandOption: true, describe: 'Command line to execute on the MID Server host' })
403
+ .option('command', { alias: 'c', type: 'string', describe: 'Command line to execute on the MID Server host' })
404
404
  .option('timeout', { type: 'number', default: DEFAULT_TIMEOUT, describe: 'Response timeout in milliseconds' })
405
405
  .option('interval', { type: 'number', default: DEFAULT_INTERVAL, describe: 'Polling interval in milliseconds' }),
406
406
  handler: wrap(async (argv, app) => {
407
- const record = await resolveMidServer(app.sdk, argv.identifier);
407
+ let record;
408
+ if (argv.identifier) {
409
+ record = await resolveMidServer(app.sdk, argv.identifier);
410
+ } else {
411
+ if (!canPrompt() || app.output.getFormat() !== FormatAuto) {
412
+ throw new Error('An identifier and --command are required outside an interactive terminal');
413
+ }
414
+ record = await interactiveList({
415
+ app,
416
+ table: AGENT_TABLE,
417
+ singular: 'MID Server',
418
+ columns: LIST_FIELDS,
419
+ limit: 50,
420
+ labelField: 'name',
421
+ message: 'Select a MID Server to execute on',
422
+ formatLabel: (candidate) => {
423
+ const name = getStringField(candidate, 'name') || getStringField(candidate, 'sys_id');
424
+ const status = getStringField(candidate, 'status');
425
+ return status ? `${name} [${status}]` : name;
426
+ },
427
+ });
428
+ if (!record) return;
429
+ }
430
+ const command = argv.command || await input({
431
+ message: 'Command to execute:',
432
+ validate: value => value.trim() ? true : 'Command is required',
433
+ });
408
434
  assertMidServerUp(record);
409
435
  const agent = agentName(record);
410
436
  const output = await app.sdk.create(QUEUE_TABLE, {
411
437
  agent,
412
438
  topic: 'Command',
413
439
  queue: 'output',
414
- name: argv.command,
415
- payload: buildCommandPayload(argv.command),
440
+ name: command,
441
+ payload: buildCommandPayload(command),
416
442
  });
417
443
  const outputSysId = unwrapSysId(output);
418
444
  if (!outputSysId) throw new Error('ServiceNow did not return the ECC Queue sys_id for the command');
@@ -422,7 +448,7 @@ export function midserversCmd(wrap) {
422
448
  const result = parseCommandResult(queueValue(response.payload));
423
449
  app.ok({
424
450
  mid_server: getStringField(record, 'name'),
425
- command: argv.command,
451
+ command,
426
452
  output: { sys_id: outputSysId, ...output },
427
453
  response: { ...response, ...result },
428
454
  }, { summary: `Executed command on MID Server '${getStringField(record, 'name')}'` });