command 'exit' alias for 'quit' #695

Massimo Melina committed Aug 5, 2024 at 16:24 UTC 706eb5093e13447df796d8bf20b090423870db82
1 file changed +10 -3
src/commands.ts
+10 -3
@@ -11,7 +11,7 @@ import { createInterface } from 'readline'
11 import { getAvailablePlugins, mapPlugins, startPlugin, stopPlugin } from './plugins'
12 import { purgeFileAttr } from './fileAttr'
13 import { downloadPlugin } from './github'
14 -import { formatBytes, formatSpeed, formatTimestamp, makeMatcher } from './cross'
14 +import { Dict, formatBytes, formatSpeed, formatTimestamp, makeMatcher } from './cross'
15 import apiMonitor from './api.monitor'
16
17 if (!argv.updating)
@@ -30,8 +30,11 @@ if (!argv.updating)
30
31 function parseCommandLine(line: string) {
32 if (!line) return
33 - const [name, ...params] = line.trim().split(/ +/)
34 - const cmd = (commands as any)[name!]
33 + let [name, ...params] = line.trim().split(/ +/)
34 + name = aliases[name!] || name
35 + let cmd = (commands as any)[name!]
36 + if (cmd.alias)
37 + cmd = (commands as any)[cmd.alias]
38 if (!cmd)
39 return console.error("cannot understand entered command, try 'help'")
40 if (cmd.cb.length > params.length)
@@ -44,6 +47,10 @@ function parseCommandLine(line: string) {
47 })
48 }
49
50 +const aliases: Dict<string> = {
51 + exit: 'quit',
52 +}
53 +
54 const commands = {
55 help: {
56 params: '',