MCPcopy Index your code
hub / github.com/nodejs/node / collectCliMdEnvVarNames

Function collectCliMdEnvVarNames

test/parallel/test-cli-node-cli-manpage-env-vars.mjs:57–96  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

55}
56
57async function collectCliMdEnvVarNames() {
58 const cliMdPath = join(rootDir, 'doc', 'api', 'cli.md');
59 const fileStream = createReadStream(cliMdPath);
60
61 let insideEnvVariablesSection = false;
62
63 const rl = createInterface({
64 input: fileStream,
65 });
66
67 const envVariableRE = /^### `(?<varName>[^`]*?)(?:=[^`]+)?`$/;
68
69 const envVarNames = new Set();
70
71 for await (const line of rl) {
72 if (line.startsWith('## ')) {
73 if (insideEnvVariablesSection) {
74 // We were in the environment variables section and we're now exiting it,
75 // so there is no need to keep checking the remaining lines,
76 // we might as well close the stream and return
77 fileStream.close();
78 return envVarNames;
79 }
80
81 // We've just entered the options section
82 insideEnvVariablesSection = line === '## Environment variables';
83 continue;
84 }
85
86 if (insideEnvVariablesSection) {
87 const match = line.match(envVariableRE);
88 if (match) {
89 const { varName } = match.groups;
90 envVarNames.add(varName);
91 }
92 }
93 }
94
95 return envVarNames;
96}

Calls 6

closeMethod · 0.65
matchMethod · 0.65
addMethod · 0.65
joinFunction · 0.50
createReadStreamFunction · 0.50
createInterfaceFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…