(configFile: string, configPath: string)
| 752 | * configPath is used as the filename in error messages |
| 753 | */ |
| 754 | export function parseConfigFile(configFile: string, configPath: string): ConfigArgs { |
| 755 | if (!configFile) { |
| 756 | return { config: configPath } |
| 757 | } |
| 758 | |
| 759 | const config = load(configFile, { |
| 760 | filename: configPath, |
| 761 | }) |
| 762 | if (!config || typeof config === "string") { |
| 763 | throw new Error(`invalid config: ${config}`) |
| 764 | } |
| 765 | |
| 766 | // We convert the config file into a set of flags. |
| 767 | // This is a temporary measure until we add a proper CLI library. |
| 768 | const configFileArgv = Object.entries(config) |
| 769 | .map(([optName, opt]) => { |
| 770 | if (opt === true) { |
| 771 | return `--${optName}` |
| 772 | } else if (Array.isArray(opt)) { |
| 773 | return opt.map((o) => `--${optName}=${o}`) |
| 774 | } |
| 775 | return `--${optName}=${opt}` |
| 776 | }) |
| 777 | .flat() |
| 778 | const args = parse(configFileArgv, { |
| 779 | configFile: configPath, |
| 780 | }) |
| 781 | return { |
| 782 | ...args, |
| 783 | config: configPath, |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | function parseBindAddr(bindAddr: string): Addr { |
| 788 | const u = new URL(`http://${bindAddr}`) |
no test coverage detected