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 contents = await readFile(filename, 'utf-8')
76 const parsed = contents?.trim() ? load(contents, { schema: YAML11_SCHEMA }) : {}
77 if (parsed) {
78 if (typeof parsed === 'object' && !Array.isArray(parsed)) {
79 const errors: string[] = []
80 const config: ProfilesByName = {}
81 for (const [profileName, profile] of Object.entries(parsed)) {
82 if (typeof(profile) === 'object' && !Array.isArray(profile)) {
83 config[profileName] = profile
84 } else {
85 errors.push(`bad profile ${profileName}; profile must be an object`)
86 }
87 }
88 if (errors.length) {
89 return fatalError(`${errors.join('\n')}\n${seeConfigDocs}`)
90 }
91 return config
92 } else {
93 return fatalError('invalid config file format\n' + seeConfigDocs)
94 }
95 }
96 return {}
97}
98
99/**

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