@samitouri / QOSami-HFS / commits / abbb604a

better code: minimize visibility

Massimo Melina committed May 14, 2023 at 23:03 UTC abbb604a6b0c4ab094240c46e835963026396318
2 files changed +5 -7
src/commands.ts
+3 -5
@@ -1,7 +1,7 @@
1 // This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
2
3 import { addAccount, getAccount, updateAccount } from './perm'
4 -import { getConfig, getConfigDefinition, setConfig } from './config'
4 +import { getConfig, configKeyExists, setConfig } from './config'
5 import _ from 'lodash'
6 import { getUpdate, update } from './update'
7 import { openAdmin } from './listen'
@@ -80,8 +80,7 @@ const commands = {
80 config: {
81 params: '<key> <value>',
82 cb(key: string, value: string) {
83 - const conf = getConfigDefinition(key)
84 - if (!conf)
83 + if (!configKeyExists(key))
84 throw "specified key doesn't exist"
85 let v: any = value
86 try { v = JSON.parse(v) }
@@ -92,8 +91,7 @@ const commands = {
91 'get-config': {
92 params: '<key>',
93 cb(key: string) {
95 - const conf = getConfigDefinition(key)
96 - if (!conf)
94 + if (!configKeyExists(key))
95 throw "specified key doesn't exist"
96 console.log(yaml.stringify(getConfig(key), { lineWidth:1000 }).trim())
97 }
src/config.ts
+2 -2
@@ -106,8 +106,8 @@ export function defineConfig<T, CT=T>(k: string, defaultValue: T, compiler?: Sub
106 return ret
107 }
108
109 -export function getConfigDefinition(k: string) {
110 - return configProps[k]
109 +export function configKeyExists(k: string) {
110 + return k in configProps
111 }
112
113 const stack: any[] = []