MCPcopy Create free account
hub / github.com/SmartThingsCommunity/smartthings-cli / loadConfigFile

Function loadConfigFile

src/lib/cli-config.ts:70–96  ·  view source on GitHub ↗
(filename: string)

Source from the content-addressed store, hash-verified

68}
69
70export const loadConfigFile = async (filename: string): Promise<ProfilesByName> => {
71 if (!yamlExists(filename)) {
72 return {}
73 }
74
75 const parsed = yaml.load(await readFile(filename, 'utf-8'))
76 if (parsed) {
77 if (typeof parsed === 'object' && !Array.isArray(parsed)) {
78 const errors: string[] = []
79 const config: ProfilesByName = {}
80 for (const [profileName, profile] of Object.entries(parsed)) {
81 if (typeof(profile) === 'object' && !Array.isArray(profile)) {
82 config[profileName] = profile
83 } else {
84 errors.push(`bad profile ${profileName}; profile must be an object`)
85 }
86 }
87 if (errors.length) {
88 return fatalError(`${errors.join('\n')}\n${seeConfigDocs}`)
89 }
90 return config
91 } else {
92 return fatalError('invalid config file format\n' + seeConfigDocs)
93 }
94 }
95 return {}
96}
97
98/**
99 * Merge profiles from `preferred` and `secondary`, favoring any config entries from `preferred`

Callers 2

loadConfigFunction · 0.85
cli-config.test.tsFile · 0.85

Calls 2

yamlExistsFunction · 0.85
fatalErrorFunction · 0.85

Tested by

no test coverage detected