diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-08-07 23:06:52 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-08-07 23:06:52 +0530 |
commit | 3321e40bffc5fe47133342d63f706a005a652273 (patch) | |
tree | d3a7bef2b99d7302a39fd606d10a1469305e7845 /packages/taler-wallet-core/src/util | |
parent | 45259427776cbacde5548e89776fdf52828f6434 (diff) | |
download | wallet-core-3321e40bffc5fe47133342d63f706a005a652273.tar.xz |
integration testing tweaks, rerun-payment-multiple scenario
Diffstat (limited to 'packages/taler-wallet-core/src/util')
-rw-r--r-- | packages/taler-wallet-core/src/util/talerconfig.ts | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/packages/taler-wallet-core/src/util/talerconfig.ts b/packages/taler-wallet-core/src/util/talerconfig.ts index 8c740e1e2..e9a67287c 100644 --- a/packages/taler-wallet-core/src/util/talerconfig.ts +++ b/packages/taler-wallet-core/src/util/talerconfig.ts @@ -26,7 +26,6 @@ import { AmountJson } from "./amounts"; import * as Amounts from "./amounts"; import fs from "fs"; -import { acceptExchangeTermsOfService } from "../operations/exchanges"; export class ConfigError extends Error { constructor(message: string) { @@ -56,6 +55,26 @@ export class ConfigValue<T> { } return this.converter(this.val); } + + orUndefined(): T | undefined { + if (this.val !== undefined) { + return this.converter(this.val); + } else { + return undefined; + } + } + + orDefault(v: T): T | undefined { + if (this.val !== undefined) { + return this.converter(this.val); + } else { + return v; + } + } + + isDefined(): boolean { + return this.val !== undefined; + } } /** @@ -197,7 +216,7 @@ export class Configuration { getString(section: string, option: string): ConfigValue<string> { const secNorm = section.toUpperCase(); const optNorm = option.toUpperCase(); - const val = (this.sectionMap[section] ?? {})[optNorm]; + const val = (this.sectionMap[secNorm] ?? {})[optNorm]; return new ConfigValue(secNorm, optNorm, val, (x) => x); } @@ -210,6 +229,36 @@ export class Configuration { ); } + getYesNo(section: string, option: string): ConfigValue<boolean> { + const secNorm = section.toUpperCase(); + const optNorm = option.toUpperCase(); + const val = (this.sectionMap[secNorm] ?? {})[optNorm]; + const convert = (x: string): boolean => { + x = x.toLowerCase(); + if (x === "yes") { + return true; + } else if (x === "no") { + return false; + } + throw Error(`invalid config value for [${secNorm}]/${optNorm}, expected yes/no`); + }; + return new ConfigValue(secNorm, optNorm, val, convert); + } + + getNumber(section: string, option: string): ConfigValue<number> { + const secNorm = section.toUpperCase(); + const optNorm = option.toUpperCase(); + const val = (this.sectionMap[secNorm] ?? {})[optNorm]; + const convert = (x: string): number => { + try { + return Number.parseInt(x, 10); + } catch (e) { + throw Error(`invalid config value for [${secNorm}]/${optNorm}, expected number`); + } + }; + return new ConfigValue(secNorm, optNorm, val, convert); + } + lookupVariable(x: string, depth: number = 0): string | undefined { // We loop up options in PATHS in upper case, as option names // are case insensitive |