| 1012 | } |
| 1013 | |
| 1014 | #createCommandApi() { |
| 1015 | const commandRegistry = { |
| 1016 | add: this.addCommand, |
| 1017 | execute: this.execCommand, |
| 1018 | remove: this.removeCommand, |
| 1019 | list: this.listCommands, |
| 1020 | }; |
| 1021 | |
| 1022 | const addCommand = (descriptor) => { |
| 1023 | try { |
| 1024 | return this.addCommand(descriptor); |
| 1025 | } catch (error) { |
| 1026 | console.error("Failed to add command", descriptor?.name); |
| 1027 | throw error; |
| 1028 | } |
| 1029 | }; |
| 1030 | |
| 1031 | const removeCommand = (name) => { |
| 1032 | if (!name) return; |
| 1033 | this.removeCommand(name); |
| 1034 | }; |
| 1035 | |
| 1036 | return { |
| 1037 | addCommand, |
| 1038 | removeCommand, |
| 1039 | get registry() { |
| 1040 | return commandRegistry; |
| 1041 | }, |
| 1042 | }; |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | const acode = new Acode(); |