MCPcopy Create free account
hub / github.com/EvilFreelancer/openapi-to-cli / saveProfile

Method saveProfile

src/profile-store.ts:137–172  ·  view source on GitHub ↗
(
    cwd: string,
    profile: Profile,
    options?: {
      makeCurrent?: boolean;
    }
  )

Source from the content-addressed store, hash-verified

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");

Callers 2

runAddProfileFunction · 0.80

Calls 5

getConfigPathsMethod · 0.95
ensureConfigDirMethod · 0.95
readIniMethod · 0.95
writeFileSyncMethod · 0.65

Tested by

no test coverage detected