better code

Massimo Melina committed Jan 26, 2023 at 23:53 UTC e015d961d18108626d4ab1ff5a775b94ce6800a8
1 file changed +6 -6
src/commands.ts
+6 -6
@@ -30,7 +30,7 @@ function parseCommandLine(line: string) {
30 return console.error("cannot understand entered command, try 'help'")
31 if (cmd.cb.length > params.length)
32 return console.error("insufficient parameters, expected: " + cmd.params)
33 - cmd.cb(...params).then(() =>console.log("+++ command executed"),
33 + Promise.resolve(cmd.cb(...params)).then(() => console.log("+++ command executed"),
34 (err: any) => {
35 if (typeof err === 'string')
36 console.error("command failed:", err)
@@ -42,7 +42,7 @@ function parseCommandLine(line: string) {
42 const commands = {
43 help: {
44 params: '',
45 - async cb() {
45 + cb() {
46 console.log("supported commands:",
47 ..._.map(commands, ({ params }, name) =>
48 '\n - ' + name + ' ' + params))
@@ -78,7 +78,7 @@ const commands = {
78 },
79 config: {
80 params: '<key> <value>',
81 - async cb(key: string, value: string) {
81 + cb(key: string, value: string) {
82 const conf = getConfigDefinition(key)
83 if (!conf)
84 throw "specified key doesn't exist"
@@ -90,7 +90,7 @@ const commands = {
90 },
91 'show-config': {
92 params: '<key>',
93 - async cb(key: string) {
93 + cb(key: string) {
94 const conf = getConfigDefinition(key)
95 if (!conf)
96 throw "specified key doesn't exist"
@@ -99,7 +99,7 @@ const commands = {
99 },
100 quit: {
101 params: '',
102 - async cb() {
102 + cb() {
103 process.exit(0)
104 }
105 },
@@ -116,7 +116,7 @@ const commands = {
116 },
117 version: {
118 params: '',
119 - async cb() {
119 + cb() {
120 console.log(VERSION)
121 console.log(BUILD_TIMESTAMP)
122 }