(file: CredentialsFile)
| 68 | } |
| 69 | |
| 70 | export function serializeCredentials(file: CredentialsFile): string { |
| 71 | const orderedSections = Object.keys(file).sort((a, b) => { |
| 72 | if (a === DEFAULT_PROFILE) return -1; |
| 73 | if (b === DEFAULT_PROFILE) return 1; |
| 74 | return a.localeCompare(b); |
| 75 | }); |
| 76 | const lines: string[] = []; |
| 77 | for (const section of orderedSections) { |
| 78 | const entry = file[section]; |
| 79 | if (!entry) continue; |
| 80 | lines.push(`[${section}]`); |
| 81 | const fields = Object.keys(entry).sort() as Array<keyof ProfileEntry>; |
| 82 | for (const field of fields) { |
| 83 | const value = entry[field]; |
| 84 | if (value === undefined || value === '') continue; |
| 85 | lines.push(`${FIELD_TO_FILE_KEY[field]} = ${value}`); |
| 86 | } |
| 87 | lines.push(''); |
| 88 | } |
| 89 | return lines.join('\n').trimEnd() + '\n'; |
| 90 | } |
| 91 | |
| 92 | export function readCredentialsFile(options: CredentialsOptions = {}): CredentialsFile { |
| 93 | const path = resolvePath(options); |
no outgoing calls
no test coverage detected