(
cwd: string,
profile: Profile,
options?: {
makeCurrent?: boolean;
}
)
| 135 | } |
| 136 | |
| 137 | saveProfile( |
| 138 | cwd: string, |
| 139 | profile: Profile, |
| 140 | options?: { |
| 141 | makeCurrent?: boolean; |
| 142 | } |
| 143 | ): void { |
| 144 | const configPaths = this.getConfigPaths(cwd); |
| 145 | this.ensureConfigDir(configPaths); |
| 146 | |
| 147 | const iniData = this.readIni(cwd); |
| 148 | |
| 149 | const sectionName = profile.name; |
| 150 | const customHeadersStr = Object.keys(profile.customHeaders).length > 0 |
| 151 | ? JSON.stringify(profile.customHeaders) |
| 152 | : ""; |
| 153 | |
| 154 | iniData[sectionName] = { |
| 155 | api_base_url: profile.apiBaseUrl, |
| 156 | api_basic_auth: profile.apiBasicAuth, |
| 157 | api_bearer_token: profile.apiBearerToken, |
| 158 | openapi_spec_source: profile.openapiSpecSource, |
| 159 | openapi_spec_cache: profile.openapiSpecCache, |
| 160 | include_endpoints: profile.includeEndpoints.join(","), |
| 161 | exclude_endpoints: profile.excludeEndpoints.join(","), |
| 162 | command_prefix: profile.commandPrefix, |
| 163 | custom_headers: customHeadersStr, |
| 164 | }; |
| 165 | |
| 166 | const serialized = ini.encode(iniData); |
| 167 | this.fs.writeFileSync(configPaths.profilesIniPath, serialized); |
| 168 | |
| 169 | if (options?.makeCurrent) { |
| 170 | this.writeCurrentProfileName(configPaths, profile.name); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | private writeCurrentProfileName(configPaths: ConfigPaths, name: string): void { |
| 175 | const currentPath = path.join(configPaths.configDir, "current"); |
no test coverage detected