MCPcopy Index your code
hub / github.com/garrytan/gstack / previewOptionsFromFlags

Function previewOptionsFromFlags

make-pdf/src/cli.ts:164–191  ·  view source on GitHub ↗
(parsed: ParsedArgs)

Source from the content-addressed store, hash-verified

162}
163
164function previewOptionsFromFlags(parsed: ParsedArgs): PreviewOptions {
165 const p = parsed.positional;
166 if (p.length === 0) {
167 console.error("$P preview: missing <input.md>");
168 console.error("Usage: $P preview <input.md> [options]");
169 process.exit(ExitCode.BadArgs);
170 }
171 const f = parsed.flags;
172 const booleanFlag = (key: string, def: boolean): boolean => {
173 if (f[key] === true) return true;
174 if (f[`no-${key}`] === true) return false;
175 return def;
176 };
177 return {
178 input: p[0],
179 cover: f.cover === true,
180 toc: f.toc === true,
181 watermark: typeof f.watermark === "string" ? f.watermark : undefined,
182 noChapterBreaks: f["no-chapter-breaks"] === true,
183 confidential: booleanFlag("confidential", true),
184 allowNetwork: f["allow-network"] === true,
185 title: typeof f.title === "string" ? f.title : undefined,
186 author: typeof f.author === "string" ? f.author : undefined,
187 date: typeof f.date === "string" ? f.date : undefined,
188 quiet: f.quiet === true,
189 verbose: f.verbose === true,
190 };
191}
192
193async function main(): Promise<void> {
194 const parsed = parseArgs(process.argv);

Callers 1

mainFunction · 0.85

Calls 1

booleanFlagFunction · 0.85

Tested by

no test coverage detected