MCPcopy
hub / github.com/iterative/cml / tfCapture

Function tfCapture

src/utils.js:205–236  ·  view source on GitHub ↗
(command, args = [], options = {})

Source from the content-addressed store, hash-verified

203};
204
205const tfCapture = async (command, args = [], options = {}) => {
206 return new Promise((resolve, reject) => {
207 const stderrCollection = [];
208 const tfProc = require('child_process').spawn(command, args, options);
209 tfProc.stdout.on('data', (buf) => {
210 const parse = (line) => {
211 if (line === '') return;
212 try {
213 const { '@level': level, '@message': message } = JSON.parse(line);
214 if (level === 'error') {
215 logger.error(`terraform error: ${message}`);
216 } else {
217 logger.info(message);
218 }
219 } catch (err) {
220 logger.info(line);
221 }
222 };
223 buf.toString('utf8').split('\n').forEach(parse);
224 });
225 tfProc.stderr.on('data', (buf) => {
226 stderrCollection.push(buf);
227 });
228 tfProc.on('close', (code) => {
229 if (code !== 0) {
230 const stderrOutput = Buffer.concat(stderrCollection).toString('utf8');
231 reject(stderrOutput);
232 }
233 resolve();
234 });
235 });
236};
237
238const fileExists = (path) =>
239 fs.promises.stat(path).then(

Callers 1

applyFunction · 0.85

Calls 1

toStringMethod · 0.80

Tested by

no test coverage detected