new command: show-config

Massimo Melina committed Aug 3, 2022 at 12:43 UTC 322ec8fe3b633be74f5cb1f07e53b7166386216d
1 file changed +12 -2
server/src/commands.ts
+12 -2
@@ -1,7 +1,8 @@
1 import { addAccount, getAccount, updateAccount } from './perm'
2 -import { getConfigDefinition, setConfig } from './config'
2 +import { getConfig, getConfigDefinition, setConfig } from './config'
3 import _ from 'lodash'
4 import { getUpdate, update } from './update'
5 +import yaml from 'yaml'
6
7 console.log(`HINT: type "help" for help`)
8 require('readline').createInterface({ input: process.stdin }).on('line', (line: string) => {
@@ -12,7 +13,7 @@ require('readline').createInterface({ input: process.stdin }).on('line', (line:
13 return console.error("cannot understand entered command, try 'help'")
14 if (cmd.cb.length > params.length)
15 return console.error("insufficient parameters, expected: " + cmd.params)
15 - cmd.cb(...params).then(() =>console.log("command executed"),
16 + cmd.cb(...params).then(() =>console.log("+++ command executed"),
17 (err: any) => {
18 if (typeof err === 'string')
19 console.error("command failed:", err)
@@ -64,6 +65,15 @@ const commands = {
65 setConfig({ [key]: v })
66 }
67 },
68 + 'show-config': {
69 + params: '<key>',
70 + async cb(key: string) {
71 + const conf = getConfigDefinition(key)
72 + if (!conf)
73 + throw "specified key doesn't exist"
74 + console.log(yaml.stringify(getConfig(key), { lineWidth:1000 }).trim())
75 + }
76 + },
77 quit: {
78 params: '',
79 async cb() {