@matter/nodejs-shell 0.11.0-alpha.0-20241007-547af42a8
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/LICENSE +201 -0
- package/README.md +192 -0
- package/dist/cjs/MatterNode.js +115 -0
- package/dist/cjs/MatterNode.js.map +6 -0
- package/dist/cjs/app.js +162 -0
- package/dist/cjs/app.js.map +6 -0
- package/dist/cjs/package.json +7 -0
- package/dist/cjs/shell/Shell.js +195 -0
- package/dist/cjs/shell/Shell.js.map +6 -0
- package/dist/cjs/shell/cmd_cluster-attributes.js +310 -0
- package/dist/cjs/shell/cmd_cluster-attributes.js.map +6 -0
- package/dist/cjs/shell/cmd_cluster-commands.js +158 -0
- package/dist/cjs/shell/cmd_cluster-commands.js.map +6 -0
- package/dist/cjs/shell/cmd_cluster-events.js +104 -0
- package/dist/cjs/shell/cmd_cluster-events.js.map +6 -0
- package/dist/cjs/shell/cmd_commission.js +237 -0
- package/dist/cjs/shell/cmd_commission.js.map +6 -0
- package/dist/cjs/shell/cmd_config.js +315 -0
- package/dist/cjs/shell/cmd_config.js.map +6 -0
- package/dist/cjs/shell/cmd_discover.js +123 -0
- package/dist/cjs/shell/cmd_discover.js.map +6 -0
- package/dist/cjs/shell/cmd_identify.js +66 -0
- package/dist/cjs/shell/cmd_identify.js.map +6 -0
- package/dist/cjs/shell/cmd_nodes.js +244 -0
- package/dist/cjs/shell/cmd_nodes.js.map +6 -0
- package/dist/cjs/shell/cmd_session.js +43 -0
- package/dist/cjs/shell/cmd_session.js.map +6 -0
- package/dist/cjs/shell/cmd_subscribe.js +59 -0
- package/dist/cjs/shell/cmd_subscribe.js.map +6 -0
- package/dist/cjs/shell/cmd_tlv.js +175 -0
- package/dist/cjs/shell/cmd_tlv.js.map +6 -0
- package/dist/cjs/util/CommandlineParser.js +106 -0
- package/dist/cjs/util/CommandlineParser.js.map +6 -0
- package/dist/cjs/util/Json.js +66 -0
- package/dist/cjs/util/Json.js.map +6 -0
- package/dist/cjs/util/String.js +32 -0
- package/dist/cjs/util/String.js.map +6 -0
- package/package.json +58 -0
- package/src/MatterNode.ts +141 -0
- package/src/app.ts +158 -0
- package/src/shell/Shell.ts +184 -0
- package/src/shell/cmd_cluster-attributes.ts +340 -0
- package/src/shell/cmd_cluster-commands.ts +174 -0
- package/src/shell/cmd_cluster-events.ts +99 -0
- package/src/shell/cmd_commission.ts +273 -0
- package/src/shell/cmd_config.ts +366 -0
- package/src/shell/cmd_discover.ts +127 -0
- package/src/shell/cmd_identify.ts +51 -0
- package/src/shell/cmd_nodes.ts +249 -0
- package/src/shell/cmd_session.ts +23 -0
- package/src/shell/cmd_subscribe.ts +43 -0
- package/src/shell/cmd_tlv.ts +169 -0
- package/src/tsconfig.json +22 -0
- package/src/util/CommandlineParser.ts +123 -0
- package/src/util/Json.ts +50 -0
- package/src/util/String.ts +9 -0
package/dist/cjs/app.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var app_exports = {};
|
|
31
|
+
__export(app_exports, {
|
|
32
|
+
exit: () => exit,
|
|
33
|
+
setLogLevel: () => setLogLevel
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(app_exports);
|
|
36
|
+
var import_general = require("@matter/general");
|
|
37
|
+
var import_nodejs = require("@matter/nodejs");
|
|
38
|
+
var import_nodejs_ble = require("@matter/nodejs-ble");
|
|
39
|
+
var import_protocol = require("@matter/protocol");
|
|
40
|
+
var import_yargs = __toESM(require("yargs/yargs"));
|
|
41
|
+
var import_MatterNode = require("./MatterNode.js");
|
|
42
|
+
var import_Shell = require("./shell/Shell");
|
|
43
|
+
/**
|
|
44
|
+
* @license
|
|
45
|
+
* Copyright 2022-2024 Matter.js Authors
|
|
46
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
47
|
+
*/
|
|
48
|
+
const PROMPT = "matter> ";
|
|
49
|
+
const logger = import_general.Logger.get("Shell");
|
|
50
|
+
if (process.stdin?.isTTY) import_general.Logger.format = import_general.LogFormat.ANSI;
|
|
51
|
+
let theNode;
|
|
52
|
+
function setLogLevel(identifier, level) {
|
|
53
|
+
let logLevel = import_general.LogLevel.INFO;
|
|
54
|
+
switch (level) {
|
|
55
|
+
case "fatal":
|
|
56
|
+
logLevel = import_general.LogLevel.FATAL;
|
|
57
|
+
break;
|
|
58
|
+
case "error":
|
|
59
|
+
logLevel = import_general.LogLevel.ERROR;
|
|
60
|
+
break;
|
|
61
|
+
case "warn":
|
|
62
|
+
logLevel = import_general.LogLevel.WARN;
|
|
63
|
+
break;
|
|
64
|
+
case "debug":
|
|
65
|
+
logLevel = import_general.LogLevel.DEBUG;
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
import_general.Logger.setDefaultLoglevelForLogger(identifier, logLevel);
|
|
69
|
+
}
|
|
70
|
+
async function main() {
|
|
71
|
+
const yargsInstance = (0, import_yargs.default)(process.argv.slice(2)).command(
|
|
72
|
+
"* [node-num] [node-type]",
|
|
73
|
+
"Matter Node Shell",
|
|
74
|
+
(yargs2) => {
|
|
75
|
+
return yargs2.positional("node-num", {
|
|
76
|
+
describe: "Node number for storage",
|
|
77
|
+
default: 0,
|
|
78
|
+
type: "number"
|
|
79
|
+
}).positional("node-type", {
|
|
80
|
+
describe: "Type of the node",
|
|
81
|
+
choices: ["controller"],
|
|
82
|
+
default: "controller",
|
|
83
|
+
type: "string"
|
|
84
|
+
}).options({
|
|
85
|
+
ble: {
|
|
86
|
+
description: "Enable BLE support.",
|
|
87
|
+
type: "boolean"
|
|
88
|
+
},
|
|
89
|
+
bleHciId: {
|
|
90
|
+
description: "HCI ID of the BLE adapter to use. The provided value will be persisted for future runs.",
|
|
91
|
+
type: "number",
|
|
92
|
+
default: 0
|
|
93
|
+
},
|
|
94
|
+
factoryReset: {
|
|
95
|
+
description: "Factory-Reset storage of this node.",
|
|
96
|
+
default: false,
|
|
97
|
+
type: "boolean"
|
|
98
|
+
},
|
|
99
|
+
netInterface: {
|
|
100
|
+
description: "Network interface to use for MDNS announcements and scanning.",
|
|
101
|
+
type: "string",
|
|
102
|
+
default: void 0
|
|
103
|
+
},
|
|
104
|
+
logfile: {
|
|
105
|
+
description: "Logfile to use to log to. By Default debug loglevel is logged to the file. The provided value will be persisted for future runs.",
|
|
106
|
+
type: "string",
|
|
107
|
+
default: void 0
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
async (argv) => {
|
|
112
|
+
if (argv.help) return;
|
|
113
|
+
const { nodeNum, ble, bleHciId, nodeType, factoryReset, netInterface, logfile } = argv;
|
|
114
|
+
theNode = new import_MatterNode.MatterNode(nodeNum, netInterface);
|
|
115
|
+
await theNode.initialize(factoryReset);
|
|
116
|
+
if (logfile !== void 0) {
|
|
117
|
+
await theNode.Store.set("LogFile", logfile);
|
|
118
|
+
}
|
|
119
|
+
if (theNode.Store.has("LogFile")) {
|
|
120
|
+
const storedLogFileName = await theNode.Store.get("LogFile");
|
|
121
|
+
if (storedLogFileName !== void 0) {
|
|
122
|
+
import_general.Logger.addLogger("file", await (0, import_nodejs.createFileLogger)(storedLogFileName), {
|
|
123
|
+
defaultLogLevel: await theNode.Store.get("LoglevelFile", import_general.LogLevel.DEBUG),
|
|
124
|
+
logFormat: import_general.LogFormat.PLAIN
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
setLogLevel("default", await theNode.Store.get("LogLevel", "info"));
|
|
129
|
+
const theShell = new import_Shell.Shell(theNode, nodeNum, PROMPT);
|
|
130
|
+
if (bleHciId !== void 0) {
|
|
131
|
+
await theNode.Store.set("BleHciId", bleHciId);
|
|
132
|
+
}
|
|
133
|
+
if (ble) {
|
|
134
|
+
const hciId = await theNode.Store.get("BleHciId", 0);
|
|
135
|
+
import_protocol.Ble.get = (0, import_general.singleton)(
|
|
136
|
+
() => new import_nodejs_ble.NodeJsBle({
|
|
137
|
+
hciId
|
|
138
|
+
})
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
console.log(`Started Node #${nodeNum} (Type: ${nodeType}) ${ble ? "with" : "without"} BLE`);
|
|
142
|
+
theShell.start();
|
|
143
|
+
}
|
|
144
|
+
).version(false).scriptName("shell");
|
|
145
|
+
await yargsInstance.wrap(yargsInstance.terminalWidth()).parseAsync();
|
|
146
|
+
}
|
|
147
|
+
process.on("message", function(message) {
|
|
148
|
+
console.log(`Message to shell.ts: ${message}`);
|
|
149
|
+
switch (message) {
|
|
150
|
+
case "exit":
|
|
151
|
+
exit().catch((error) => logger.error(error));
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
async function exit(code = 0) {
|
|
155
|
+
await theNode?.close();
|
|
156
|
+
process.exit(code);
|
|
157
|
+
}
|
|
158
|
+
process.on("SIGINT", () => {
|
|
159
|
+
exit().catch((error) => logger.error(error));
|
|
160
|
+
});
|
|
161
|
+
main().catch((error) => logger.error(error));
|
|
162
|
+
//# sourceMappingURL=app.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/app.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,qBAAuD;AACvD,oBAAiC;AACjC,wBAA0B;AAC1B,sBAAoB;AACpB,mBAAkB;AAClB,wBAA2B;AAC3B,mBAAsB;AAZtB;AAAA;AAAA;AAAA;AAAA;AAcA,MAAM,SAAS;AACf,MAAM,SAAS,sBAAO,IAAI,OAAO;AACjC,IAAI,QAAQ,OAAO,MAAO,uBAAO,SAAS,yBAAU;AAEpD,IAAI;AAEG,SAAS,YAAY,YAAoB,OAAqB;AACjE,MAAI,WAAW,wBAAS;AACxB,UAAQ,OAAO;AAAA,IACX,KAAK;AACD,iBAAW,wBAAS;AACpB;AAAA,IACJ,KAAK;AACD,iBAAW,wBAAS;AACpB;AAAA,IACJ,KAAK;AACD,iBAAW,wBAAS;AACpB;AAAA,IACJ,KAAK;AACD,iBAAW,wBAAS;AACpB;AAAA,EACR;AACA,wBAAO,4BAA4B,YAAY,QAAQ;AAC3D;AAKA,eAAe,OAAO;AAClB,QAAM,oBAAgB,aAAAA,SAAM,QAAQ,KAAK,MAAM,CAAC,CAAC,EAC5C;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+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var Shell_exports = {};
|
|
30
|
+
__export(Shell_exports, {
|
|
31
|
+
Shell: () => Shell
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(Shell_exports);
|
|
34
|
+
var import_general = require("@matter/general");
|
|
35
|
+
var import_fs = require("fs");
|
|
36
|
+
var import_node_readline = __toESM(require("node:readline"));
|
|
37
|
+
var import_yargs = __toESM(require("yargs/yargs"));
|
|
38
|
+
var import_app = require("../app");
|
|
39
|
+
var import_CommandlineParser = require("../util/CommandlineParser.js");
|
|
40
|
+
var import_cmd_cluster_attributes = __toESM(require("./cmd_cluster-attributes"));
|
|
41
|
+
var import_cmd_cluster_commands = __toESM(require("./cmd_cluster-commands"));
|
|
42
|
+
var import_cmd_cluster_events = __toESM(require("./cmd_cluster-events"));
|
|
43
|
+
var import_cmd_commission = __toESM(require("./cmd_commission.js"));
|
|
44
|
+
var import_cmd_config = __toESM(require("./cmd_config.js"));
|
|
45
|
+
var import_cmd_discover = __toESM(require("./cmd_discover.js"));
|
|
46
|
+
var import_cmd_identify = __toESM(require("./cmd_identify.js"));
|
|
47
|
+
var import_cmd_nodes = __toESM(require("./cmd_nodes.js"));
|
|
48
|
+
var import_cmd_session = __toESM(require("./cmd_session.js"));
|
|
49
|
+
var import_cmd_subscribe = __toESM(require("./cmd_subscribe.js"));
|
|
50
|
+
var import_cmd_tlv = __toESM(require("./cmd_tlv"));
|
|
51
|
+
/**
|
|
52
|
+
* @license
|
|
53
|
+
* Copyright 2022-2024 Matter.js Authors
|
|
54
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
55
|
+
*/
|
|
56
|
+
const MAX_HISTORY_SIZE = 1e3;
|
|
57
|
+
function exitCommand() {
|
|
58
|
+
return {
|
|
59
|
+
command: "exit",
|
|
60
|
+
describe: "Exit",
|
|
61
|
+
builder: {},
|
|
62
|
+
handler: async () => {
|
|
63
|
+
console.log("Goodbye.");
|
|
64
|
+
await (0, import_app.exit)();
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
class Shell {
|
|
69
|
+
/**
|
|
70
|
+
* Construct a new Shell object.
|
|
71
|
+
*/
|
|
72
|
+
constructor(theNode, nodeNum, prompt) {
|
|
73
|
+
this.theNode = theNode;
|
|
74
|
+
this.nodeNum = nodeNum;
|
|
75
|
+
this.prompt = prompt;
|
|
76
|
+
}
|
|
77
|
+
readline;
|
|
78
|
+
writeStream;
|
|
79
|
+
start() {
|
|
80
|
+
const history = new Array();
|
|
81
|
+
const fileName = `.matter-shell-${this.nodeNum}.history`;
|
|
82
|
+
try {
|
|
83
|
+
const historyData = (0, import_fs.readFileSync)(fileName, "utf8");
|
|
84
|
+
history.push(
|
|
85
|
+
...historyData.split("\n").map((line) => line.trim()).filter((line) => line.length)
|
|
86
|
+
);
|
|
87
|
+
history.splice(0, -MAX_HISTORY_SIZE);
|
|
88
|
+
console.log(`Loaded ${history.length} history entries from ${fileName}`);
|
|
89
|
+
} catch (e) {
|
|
90
|
+
if (e instanceof Error && "code" in e && e.code !== "ENOENT") {
|
|
91
|
+
process.stderr.write(`Error happened during history file read: ${e}
|
|
92
|
+
`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
this.writeStream = (0, import_fs.createWriteStream)(fileName, { flags: "w" });
|
|
97
|
+
this.writeStream.write(`${history.join("\n")}
|
|
98
|
+
`);
|
|
99
|
+
} catch (e) {
|
|
100
|
+
process.stderr.write(`Error happened during history file write: ${e}
|
|
101
|
+
`);
|
|
102
|
+
}
|
|
103
|
+
this.readline = import_node_readline.default.createInterface({
|
|
104
|
+
input: process.stdin,
|
|
105
|
+
output: process.stdout,
|
|
106
|
+
terminal: true,
|
|
107
|
+
prompt: this.prompt,
|
|
108
|
+
history: history.reverse(),
|
|
109
|
+
historySize: MAX_HISTORY_SIZE
|
|
110
|
+
});
|
|
111
|
+
this.readline.on("line", (cmd) => {
|
|
112
|
+
cmd = cmd.trim();
|
|
113
|
+
this.onReadLine(cmd).then((result) => result && cmd.length && this.writeStream?.write(`${cmd}
|
|
114
|
+
`)).catch((e) => {
|
|
115
|
+
process.stderr.write(`Read error: ${e}
|
|
116
|
+
`);
|
|
117
|
+
process.exit(1);
|
|
118
|
+
});
|
|
119
|
+
}).on("close", () => {
|
|
120
|
+
try {
|
|
121
|
+
this.writeStream?.end();
|
|
122
|
+
} catch (e) {
|
|
123
|
+
process.stderr.write(`Error happened during history file write: ${e}
|
|
124
|
+
`);
|
|
125
|
+
}
|
|
126
|
+
(0, import_app.exit)().then(() => process.exit(0)).catch((e) => {
|
|
127
|
+
process.stderr.write(`Close error: ${e}
|
|
128
|
+
`);
|
|
129
|
+
process.exit(1);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
this.readline.prompt();
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Method to process a line of raw cli text input.
|
|
136
|
+
*
|
|
137
|
+
* @param {string} line
|
|
138
|
+
*/
|
|
139
|
+
async onReadLine(line) {
|
|
140
|
+
let result = true;
|
|
141
|
+
if (line) {
|
|
142
|
+
let args;
|
|
143
|
+
try {
|
|
144
|
+
args = (0, import_CommandlineParser.commandlineParser)(line);
|
|
145
|
+
} catch (error) {
|
|
146
|
+
process.stderr.write(`Error happened during command parsing: ${error}
|
|
147
|
+
`);
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
const yargsInstance = (0, import_yargs.default)(args).command([
|
|
151
|
+
(0, import_cmd_commission.default)(this.theNode),
|
|
152
|
+
(0, import_cmd_config.default)(this.theNode),
|
|
153
|
+
(0, import_cmd_session.default)(this.theNode),
|
|
154
|
+
(0, import_cmd_nodes.default)(this.theNode),
|
|
155
|
+
(0, import_cmd_subscribe.default)(this.theNode),
|
|
156
|
+
(0, import_cmd_identify.default)(this.theNode),
|
|
157
|
+
(0, import_cmd_discover.default)(this.theNode),
|
|
158
|
+
(0, import_cmd_cluster_attributes.default)(this.theNode),
|
|
159
|
+
(0, import_cmd_cluster_events.default)(this.theNode),
|
|
160
|
+
(0, import_cmd_cluster_commands.default)(this.theNode),
|
|
161
|
+
(0, import_cmd_tlv.default)(),
|
|
162
|
+
exitCommand()
|
|
163
|
+
]).command({
|
|
164
|
+
command: "*",
|
|
165
|
+
handler: (argv) => {
|
|
166
|
+
argv.unhandled = true;
|
|
167
|
+
}
|
|
168
|
+
}).exitProcess(false).version(false).help("help").scriptName("").strictCommands(false).strictOptions(false).fail(false).strict(false);
|
|
169
|
+
try {
|
|
170
|
+
const argv = await yargsInstance.wrap(yargsInstance.terminalWidth()).parseAsync();
|
|
171
|
+
if (argv.unhandled) {
|
|
172
|
+
process.stderr.write(`Unknown command: ${line}
|
|
173
|
+
`);
|
|
174
|
+
yargsInstance.showHelp();
|
|
175
|
+
} else {
|
|
176
|
+
console.log("Done.");
|
|
177
|
+
}
|
|
178
|
+
} catch (error) {
|
|
179
|
+
process.stderr.write(`Error happened during command: ${error}
|
|
180
|
+
`);
|
|
181
|
+
if (error instanceof Error && error.stack) {
|
|
182
|
+
process.stderr.write(error.stack.toString());
|
|
183
|
+
process.stderr.write("\n");
|
|
184
|
+
}
|
|
185
|
+
if (!(error instanceof import_general.MatterError)) {
|
|
186
|
+
yargsInstance.showHelp();
|
|
187
|
+
result = false;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
this.readline?.prompt();
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=Shell.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/shell/Shell.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,qBAA4B;AAC5B,gBAAgD;AAChD,2BAAqB;AACrB,mBAAkB;AAElB,iBAAqB;AACrB,+BAAkC;AAClC,oCAA0B;AAC1B,kCAAwB;AACxB,gCAAsB;AACtB,4BAA0B;AAC1B,wBAAsB;AACtB,0BAAwB;AACxB,0BAAwB;AACxB,uBAAqB;AACrB,yBAAuB;AACvB,2BAAyB;AACzB,qBAAmB;AAvBnB;AAAA;AAAA;AAAA;AAAA;AAyBA,MAAM,mBAAmB;AAEzB,SAAS,cAAc;AACnB,SAAO;AAAA,IACH,SAAS;AAAA,IACT,UAAU;AAAA,IACV,SAAS,CAAC;AAAA,IACV,SAAS,YAAY;AACjB,cAAQ,IAAI,UAAU;AACtB,gBAAM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AAC,SAAO;AAAA,QACP,YAAY;AAAA,MAChB,CAAC,EACA,QAAQ;AAAA,QACL,SAAS;AAAA,QACT,SAAS,UAAQ;AACb,eAAK,YAAY;AAAA,QACrB;AAAA,MACJ,CAAC,EACA,YAAY,KAAK,EACjB,QAAQ,KAAK,EACb,KAAK,MAAM,EACX,WAAW,EAAE,EACb,eAAe,KAAK,EACpB,cAAc,KAAK,EACnB,KAAK,KAAK,EACV,OAAO,KAAK;AACjB,UAAI;AACA,cAAM,OAAO,MAAM,cAAc,KAAK,cAAc,cAAc,CAAC,EAAE,WAAW;AAEhF,YAAI,KAAK,WAAW;AAChB,kBAAQ,OAAO,MAAM,oBAAoB,IAAI;AAAA,CAAI;AACjD,wBAAc,SAAS;AAAA,QAC3B,OAAO;AACH,kBAAQ,IAAI,OAAO;AAAA,QACvB;AAAA,MACJ,SAAS,OAAO;AACZ,gBAAQ,OAAO,MAAM,kCAAkC,KAAK;AAAA,CAAI;AAChE,YAAI,iBAAiB,SAAS,MAAM,OAAO;AACvC,kBAAQ,OAAO,MAAM,MAAM,MAAM,SAAS,CAAC;AAC3C,kBAAQ,OAAO,MAAM,IAAI;AAAA,QAC7B;AACA,YAAI,EAAE,iBAAiB,6BAAc;AACjC,wBAAc,SAAS;AACvB,mBAAS;AAAA,QACb;AAAA,MACJ;AAAA,IACJ;AACA,SAAK,UAAU,OAAO;AACtB,WAAO;AAAA,EACX;AACJ;",
|
|
5
|
+
"names": ["readline", "yargs", "cmdCommission", "cmdConfig", "cmdSession", "cmdNodes", "cmdSubscribe", "cmdIdentify", "cmdDiscover", "cmdAttributes", "cmdEvents", "cmdCommands", "cmdTlv"]
|
|
6
|
+
}
|