diff --git a/src/argv.js b/src/argv.js index 41a76971..2ee910d7 100755 --- a/src/argv.js +++ b/src/argv.js @@ -1,5 +1,6 @@ 'use strict'; +const fs = require('fs'); const config = require('config'); const yargs = require('yargs'); const { hideBin } = require('yargs/helpers'); @@ -61,6 +62,11 @@ const { argv } = yargs(hideBin(process.argv)) type: 'array', alias: ['include-channel', 'channels', 'channel'], }) + .option('entities-file', { + describe: 'Include channels and networks from a file, one slug per line, networks prefixed with _ (e.g. _manyvids), # for comments', + type: 'string', + alias: ['entity-file', 'channels-file', 'networks-file'], + }) .option('exclude-channels', { describe: 'Channel not to scrape (overrides configuration)', type: 'array', @@ -531,4 +537,25 @@ const { argv } = yargs(hideBin(process.argv)) .coerce('flush-before', interpretDate) .coerce('actors-update', (after) => interpretDate(after, true)); +// merged into --channels and --networks, so everything that checks those (update scrapes, stream, entity resolve) picks the file up +if (argv.entitiesFile) { + const slugs = fs.readFileSync(argv.entitiesFile, 'utf-8') + .split('\n') + .map((line) => line.replace(/#.*/, '').trim()) + .filter(Boolean); + + const networks = slugs.filter((slug) => slug.startsWith('_')).map((slug) => slug.slice(1)); + const channels = slugs.filter((slug) => !slug.startsWith('_')); + + if (networks.length > 0) { + argv.networks = Array.from(new Set([...(argv.networks || []), ...networks])); + argv.includeNetworks = argv.networks; + } + + if (channels.length > 0) { + argv.channels = Array.from(new Set([...(argv.channels || []), ...channels])); + argv.includeChannels = argv.channels; + } +} + module.exports = argv;