MCPcopy Index your code
hub / github.com/cameri/nostream / parseCliArgs

Function parseCliArgs

src/scripts/export-events.ts:127–183  ·  view source on GitHub ↗
(args: string[])

Source from the content-addressed store, hash-verified

125}
126
127export const parseCliArgs = (args: string[]): ExportCliOptions => {
128 let compress = false
129 let format: CompressionFormat | undefined
130 let outputFilePath: string | undefined
131
132 if (args.includes('--help') || args.includes('-h')) {
133 return {
134 compress,
135 format,
136 outputFilePath: DEFAULT_OUTPUT_FILE_PATH,
137 showHelp: true,
138 }
139 }
140
141 for (let index = 0; index < args.length; index++) {
142 const arg = args[index]
143
144 if (arg === '--compress' || arg === '-z') {
145 compress = true
146 continue
147 }
148
149 if (arg === '--format' || arg.startsWith('--format=')) {
150 const [rawFormat, nextIndex] = getOptionValue('--format', args, index)
151 format = parseCompressionFormat(rawFormat)
152 index = nextIndex
153 continue
154 }
155
156 if (arg.startsWith('-')) {
157 throw new Error(`Unknown option: ${arg}`)
158 }
159
160 if (outputFilePath) {
161 throw new Error(`Unexpected extra argument: ${arg}`)
162 }
163
164 outputFilePath = arg
165 }
166
167 if (!compress && format) {
168 throw new Error('--format requires --compress')
169 }
170
171 outputFilePath = outputFilePath ?? DEFAULT_OUTPUT_FILE_PATH
172
173 if (compress && !format) {
174 format = getCompressionFormatFromExtension(outputFilePath) ?? CompressionFormat.GZIP
175 }
176
177 return {
178 compress,
179 format,
180 outputFilePath,
181 showHelp: false,
182 }
183}
184

Callers 2

runExportEventsFunction · 0.70

Calls 3

parseCompressionFormatFunction · 0.90
getOptionValueFunction · 0.70

Tested by

no test coverage detected