import { readFileSync } from 'fs';
const ini = await npm('ini');
const awsConf = `${process.env.HOME}/.aws/config`;
const config = ini.parse(readFileSync(awsConf, 'utf-8'));
const currentMarker = ' ★';
const currentProfile = env['AWS_PROFILE'];
const sections = Object.keys(config).reduce(function (filtered, section) {
if (section.startsWith('profile ')) {
let profileName = section.replace('profile ', '');
if (profileName == currentProfile) {
profileName += currentMarker;
}
filtered.push(profileName);
}
return filtered;
}, []);
const profile = await arg(
{
placeholder: 'Select profile',
hint: `parsed from ${awsConf}`,
},
sections.sort()
);
await cli('set-env-var', 'AWS_PROFILE', profile.replace(currentMarker, ''));