goblin-laboratory 4.7.3 → 4.8.0

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);
@@ -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,55 @@ 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
+
405
454
  async $tool(tool) {
406
455
  if (tool === 'man') {
407
- return {...this._tools};
456
+ return {
457
+ ...Object.keys(this._tools).reduce((obj, tool) => {
458
+ obj[tool] = null;
459
+ return obj;
460
+ }, {}),
461
+ };
462
+ }
463
+ if (tool === 'buslog') {
464
+ const {resp} = this.quest;
465
+ const registry = resp.getCommandsRegistry();
466
+ return Object.keys(registry)
467
+ .filter((cmd) => /^buslog[.][^.]+[.]verbosity$/.test(cmd))
468
+ .reduce((autocomp, cmd) => {
469
+ autocomp[cmd.split('.')[1]] = {
470
+ '0': null,
471
+ '1': null,
472
+ '2': null,
473
+ '3': null,
474
+ };
475
+ return autocomp;
476
+ }, {});
408
477
  }
409
478
  return {};
410
479
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "goblin-laboratory",
3
- "version": "4.7.3",
3
+ "version": "4.8.0",
4
4
  "description": "Laboratory",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -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,