@indra.ai/deva 1.5.39 → 1.5.41
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/index.js +25 -12
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1554,6 +1554,7 @@ class Deva {
|
|
|
1554
1554
|
***************/
|
|
1555
1555
|
help(msg, help_dir) {
|
|
1556
1556
|
return new Promise((resolve, reject) => {
|
|
1557
|
+
let helpDoc = false;
|
|
1557
1558
|
const id = this.lib.uid();
|
|
1558
1559
|
this.zone('help', id);
|
|
1559
1560
|
if (!this._active) return resolve(this._messages.offline);
|
|
@@ -1563,30 +1564,42 @@ class Deva {
|
|
|
1563
1564
|
this.state('help', id);
|
|
1564
1565
|
this.context('help', id);
|
|
1565
1566
|
const params = msg.split(' '); // split the msg into an array by spaces.
|
|
1566
|
-
let helpFile = 'main', helpDoc = false; // set default help file
|
|
1567
|
-
if (params[0]) helpFile = params[0]; // check the msg for a help file
|
|
1568
|
-
if (params[1]) helpFile = `${params[0]}_${params[1]}`;
|
|
1569
1567
|
|
|
1570
|
-
const splitText =
|
|
1568
|
+
const splitText = params[0].split(':');
|
|
1571
1569
|
const part = splitText[1] ? splitText[1].toUpperCase() : 'MAIN';
|
|
1572
|
-
|
|
1573
|
-
|
|
1570
|
+
const helpFile = splitText[0] ? splitText[0] : 'main';
|
|
1571
|
+
|
|
1574
1572
|
const helpPath = this.lib.path.join(help_dir, 'help', `${helpFile}.feecting`);
|
|
1575
|
-
|
|
1573
|
+
|
|
1576
1574
|
try {
|
|
1575
|
+
this.state('try', `help:${id}`);
|
|
1576
|
+
|
|
1577
|
+
// check if help file exists first and resolve if no file
|
|
1577
1578
|
const helpExists = this.lib.fs.existsSync(helpPath); // check if help file exists
|
|
1578
1579
|
if (!helpExists) {
|
|
1579
1580
|
this.state('return', `${this._messages.help_not_found}:${id}`);
|
|
1580
1581
|
return resolve(this._messages.help_not_found);
|
|
1581
1582
|
}
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
this.
|
|
1585
|
-
|
|
1586
|
-
|
|
1583
|
+
|
|
1584
|
+
// get the help file and check to make sure the part we are looking for exists.
|
|
1585
|
+
const helpFile = this.lib.fs.readFileSync(helpPath, 'utf8');
|
|
1586
|
+
const helpPart = helpFile.split(`::BEGIN:${part}`);
|
|
1587
|
+
if (!helpPart[1]) {
|
|
1588
|
+
this.state('return', `${this._messages.help_not_found}:${id}`);
|
|
1589
|
+
resolve(this._messages.help_not_found);
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
// last set the help doc and split out the selected part.
|
|
1593
|
+
helpDoc = helpFile.split(`::BEGIN:${part}`)[1].split(`::END:${part}`)[0];
|
|
1594
|
+
}
|
|
1595
|
+
catch(e) {
|
|
1587
1596
|
this.state('catch', `help:${id}`);
|
|
1588
1597
|
return this.error(e, msg, reject);
|
|
1589
1598
|
}
|
|
1599
|
+
finally {
|
|
1600
|
+
this.state('return', `help:${id}`);
|
|
1601
|
+
return resolve(helpDoc);
|
|
1602
|
+
}
|
|
1590
1603
|
});
|
|
1591
1604
|
}
|
|
1592
1605
|
|