goblin-laboratory 4.7.3 → 4.9.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/lib/termux.js CHANGED
@@ -240,7 +240,7 @@ class Termux extends Elf.Alone {
240
240
  const tool = getTool(this._tools, name);
241
241
  const {required, optional} = tool.options.params;
242
242
  let args = required.concat(optional).reduce((args, arg, index) => {
243
- args[arg] = params[index];
243
+ args[arg] = arg.startsWith('...') ? params.slice(index) : params[index];
244
244
  return args;
245
245
  }, {});
246
246
  this.logic.beginCommand(null, null, tool.name);
@@ -297,9 +297,9 @@ class Termux extends Elf.Alone {
297
297
 
298
298
  async askForCompletion(input) {
299
299
  const prompt = getPrompt(this.user);
300
- const tools = Object.keys(this._tools).filter((tool) =>
301
- tool.startsWith(input)
302
- );
300
+ const tools = Object.keys(this._tools)
301
+ .filter((tool) => tool.startsWith(input))
302
+ .sort();
303
303
  this.logic.askForCompletion(prompt, input, tools);
304
304
 
305
305
  const {completion} = this.state;
@@ -318,15 +318,38 @@ class Termux extends Elf.Alone {
318
318
  return;
319
319
  }
320
320
 
321
- const desc = await this.quest.cmd(`${name}.$tool`, {tool});
321
+ let desc = await this.quest.cmd(`${name}.$tool`, {tool});
322
322
  if (items.length === 1) {
323
323
  this.logic.askForCompletion(prompt, input, Object.keys(desc));
324
324
  return;
325
325
  }
326
326
 
327
- const cmds = Object.keys(desc)
328
- .filter((option) => option.startsWith(items[1]))
329
- .map((option) => `${tool} ${option}`);
327
+ let cmds = Object.keys(desc);
328
+ items.shift();
329
+
330
+ for (const item of items) {
331
+ if (item in desc) {
332
+ desc = desc[item];
333
+ if (!Array.isArray(desc)) {
334
+ cmds = Object.keys(desc);
335
+ continue;
336
+ }
337
+ cmds = [
338
+ 'Arguments:',
339
+ ...desc.map((obj) =>
340
+ Object.entries(obj)
341
+ .map(([k, v]) => `${k}:${v}`)
342
+ .join(' ')
343
+ ),
344
+ ];
345
+ break;
346
+ }
347
+ const slice = items.slice(0, -1).join(' ');
348
+ cmds = cmds
349
+ .filter((option) => option.startsWith(item))
350
+ .map((option) => `${tool} ${slice.length ? `${slice} ` : ''}${option}`);
351
+ }
352
+
330
353
  this.logic.askForCompletion(prompt, input.trim(), cmds);
331
354
  }
332
355
 
@@ -402,9 +425,112 @@ class Termux extends Elf.Alone {
402
425
  return result;
403
426
  }
404
427
 
428
+ async buslog$tool(horde, verbosityLevel, ...moduleNames) {
429
+ const {topology} = require('xcraft-core-etc')().load('xcraft-core-horde');
430
+ const _xcraftRPC = topology?.[horde]?.passive;
431
+
432
+ /* FIXME: must be moved on the server side */
433
+ if (_xcraftRPC && this.user.rank !== 'admin') {
434
+ throw new Error('Forbidden');
435
+ }
436
+
437
+ verbosityLevel = parseInt(verbosityLevel);
438
+ if (verbosityLevel >= 0 && verbosityLevel < 4) {
439
+ await this.quest.cmd(`buslog.${horde}.verbosity`, {
440
+ level: verbosityLevel,
441
+ _xcraftRPC,
442
+ });
443
+ }
444
+ if (Array.isArray(moduleNames)) {
445
+ moduleNames = moduleNames.filter((entry) => !!entry);
446
+ await this.quest.cmd(`buslog.${horde}.modulenames`, {
447
+ modulenames: moduleNames,
448
+ _xcraftRPC,
449
+ });
450
+ }
451
+ return '';
452
+ }
453
+
454
+ async metrics$tool(horde, output) {
455
+ const {topology} = require('xcraft-core-etc')().load('xcraft-core-horde');
456
+ const _xcraftRPC = topology?.[horde]?.passive;
457
+
458
+ /* FIXME: must be moved on the server side */
459
+ if (_xcraftRPC && this.user.rank !== 'admin') {
460
+ throw new Error('Forbidden');
461
+ }
462
+
463
+ let metrics = await this.quest.cmd(`bus.${horde}.xcraftMetrics`, {
464
+ from: this.id,
465
+ _xcraftRPC,
466
+ });
467
+ metrics = JSON.stringify(metrics, null, 2);
468
+
469
+ if (!output) {
470
+ return metrics;
471
+ }
472
+
473
+ const fse = require('fs-extra');
474
+ await fse.writeFile(output, metrics);
475
+ return 'Metrics saved to: ' + output;
476
+ }
477
+
478
+ async heapdump$tool(horde) {
479
+ const {topology} = require('xcraft-core-etc')().load('xcraft-core-horde');
480
+ const _xcraftRPC = topology?.[horde]?.passive;
481
+
482
+ /* FIXME: must be moved on the server side */
483
+ if (_xcraftRPC && this.user.rank !== 'admin') {
484
+ throw new Error('Forbidden');
485
+ }
486
+
487
+ const output = await this.quest.cmd(`bus.${horde}.heapdump`, {_xcraftRPC});
488
+ return output;
489
+ }
490
+
405
491
  async $tool(tool) {
406
492
  if (tool === 'man') {
407
- return {...this._tools};
493
+ return {
494
+ ...Object.keys(this._tools).reduce((obj, tool) => {
495
+ obj[tool] = null;
496
+ return obj;
497
+ }, {}),
498
+ };
499
+ }
500
+ if (tool === 'buslog') {
501
+ const {resp} = this.quest;
502
+ const registry = resp.getCommandsRegistry();
503
+ return Object.keys(registry)
504
+ .filter((cmd) => /^buslog[.][^.]+[.]verbosity$/.test(cmd))
505
+ .reduce((autocomp, cmd) => {
506
+ autocomp[cmd.split('.')[1]] = {
507
+ '0': null,
508
+ '1': null,
509
+ '2': null,
510
+ '3': null,
511
+ };
512
+ return autocomp;
513
+ }, {});
514
+ }
515
+ if (tool === 'metrics') {
516
+ const {resp} = this.quest;
517
+ const registry = resp.getCommandsRegistry();
518
+ return Object.keys(registry)
519
+ .filter((cmd) => /^bus[.][^.]+[.]xcraftMetrics$/.test(cmd))
520
+ .reduce((autocomp, cmd) => {
521
+ autocomp[cmd.split('.')[1]] = null;
522
+ return autocomp;
523
+ }, {});
524
+ }
525
+ if (tool === 'heapdump') {
526
+ const {resp} = this.quest;
527
+ const registry = resp.getCommandsRegistry();
528
+ return Object.keys(registry)
529
+ .filter((cmd) => /^bus[.][^.]+[.]heapdump$/.test(cmd))
530
+ .reduce((autocomp, cmd) => {
531
+ autocomp[cmd.split('.')[1]] = null;
532
+ return autocomp;
533
+ }, {});
408
534
  }
409
535
  return {};
410
536
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "goblin-laboratory",
3
- "version": "4.7.3",
3
+ "version": "4.9.1",
4
4
  "description": "Laboratory",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -26,6 +26,7 @@
26
26
  }
27
27
  },
28
28
  "dependencies": {
29
+ "fs-extra": "^11.3.3",
29
30
  "goblin-theme": "^2.0.0",
30
31
  "xcraft-core-goblin": "^5.0.0",
31
32
  "xcraft-core-log": "^2.2.0",
@@ -57,4 +58,4 @@
57
58
  "xcraft-traverse": "^0.7.0"
58
59
  },
59
60
  "prettier": "xcraft-dev-prettier"
60
- }
61
+ }
@@ -34,7 +34,7 @@ export default function (
34
34
  ) {
35
35
  return connect(
36
36
  withShredder(mapStateToProps),
37
- mapDispatchToProps,
37
+ mapDispatchToProps || (() => ({})),
38
38
  mergeProps,
39
39
  {
40
40
  pure: true,