1
0
mirror of https://github.com/nttgin/BGPalerter.git synced 2024-05-19 06:50:08 +00:00

added argument p and pf to generate complete prefix list from simple prefix list (#43)

* added argument p and pf to generate complete prefix list from simple prefix list
* updated documentation with -p and -pf arguments
This commit is contained in:
Massimo Candela
2019-10-27 13:39:54 +01:00
committed by GitHub
parent 4c196cb5c3
commit f33bd4b4e6
4 changed files with 51 additions and 15 deletions

View File

@@ -53,11 +53,19 @@ const params = yargs
.nargs('e', 1)
.describe('e', 'Prefixes to exclude')
.alias('p', 'prefixes')
.nargs('p', 1)
.describe('p', 'Prefixes to include')
.alias('pf', 'prefixes-file')
.nargs('pf', 1)
.describe('pf', 'File containing the prefixes to include')
.alias('i', 'ignore-delegated')
.nargs('i', 0)
.describe('i', 'Ignore delegated prefixes')
.demandOption(['o', 'a'])
.demandOption(['o']);
})
.example('$0 generate -a 2914 -o prefixes.yml', 'Generate prefixes for AS2914')
@@ -70,12 +78,28 @@ const params = yargs
switch(params._[0]) {
case "generate":
const generatePrefixes = require("./generatePrefixesList");
let prefixes = null;
if (params.p && params.pf) {
throw new Error("The argument -p is not compatible with the argument -pf");
} else if (params.p) {
prefixes = params.p.split(",");
} else if (params.pf) {
const fs = require("fs");
if (fs.existsSync(params.pf)) {
prefixes = fs.readFileSync(params.pf, 'utf8').split(/\r?\n/).filter(i => i && true);
} else {
throw new Error("The prefix list file (-pf) is not readable");
}
}
generatePrefixes(
params.a.toString(),
(params.a) ? params.a.toString().split(",") : null,
params.o,
(params.e || "").split(","),
params.i || false
params.i || false,
prefixes
);
break;
default: // Run monitor