support reading headers from a file instead of cli args
This commit is contained in:
parent
7eecc9ca3f
commit
40a9f30755
2 changed files with 53 additions and 1 deletions
|
@ -428,6 +428,29 @@ export async function parseCommandLineArgs(args: string[], usage: string) {
|
|||
args.splice(i, 2)
|
||||
// Do not increment i, as the array has shifted
|
||||
continue
|
||||
} else if (args[i] === '--headerFile' && i < args.length - 1) {
|
||||
const filePath = args[i + 1]
|
||||
try {
|
||||
const fileContent = fs.readFileSync(filePath, 'utf8')
|
||||
const lines = fileContent.split('\n')
|
||||
for (const line of lines) {
|
||||
const trimmedLine = line.trim()
|
||||
if (trimmedLine && !trimmedLine.startsWith('#')) {
|
||||
const match = trimmedLine.match(/^([A-Za-z0-9_-]+):(.*)$/)
|
||||
if (match) {
|
||||
headers[match[1]] = match[2]
|
||||
} else {
|
||||
log(`Warning: ignoring invalid header in file: ${trimmedLine}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
log(`Loaded headers from file: ${filePath}`)
|
||||
} catch (error) {
|
||||
log(`Error reading header file ${filePath}: ${error.message}`)
|
||||
}
|
||||
args.splice(i, 2)
|
||||
// Do not increment i, as the array has shifted
|
||||
continue
|
||||
}
|
||||
i++
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue