Add yargs integration for command line flags
Add yargs integration for command line flags in preparation for adding a
more. yargs doesn't appear to support the existing flags containing
minus ('-') characters in the middle, i.e. --no-validation and
--filtered-zones so these have been renamed to --no_validation and
--included_zones respectively.
--included_zones now takes a list without quotes or commas.
This change also updates the README.md example to demonstrate the
--included_zones flag.
diff --git a/index.js b/index.js
index 56e8c02..e6f50f1 100644
--- a/index.js
+++ b/index.js
@@ -11,6 +11,7 @@
var jsts = require('jsts')
var rimraf = require('rimraf')
var overpass = require('query-overpass')
+var yargs = require('yargs')
const ProgressStats = require('./progressStats')
@@ -18,13 +19,26 @@
var zoneCfg = require('./timezones.json')
var expectedZoneOverlaps = require('./expectedZoneOverlaps.json')
+const argv = yargs
+ .option('included_zones', {
+ description: 'Include specified zones',
+ type: 'array'
+ })
+ .option('no_validation', {
+ description: 'Skip validation',
+ type: 'boolean'
+ })
+ .help()
+ .strict()
+ .alias('help', 'h')
+ .argv
+
// allow building of only a specified zones
-var filteredIndex = process.argv.indexOf('--filtered-zones')
-let filteredZones = []
-if (filteredIndex > -1 && process.argv[filteredIndex + 1]) {
- filteredZones = process.argv[filteredIndex + 1].split(',')
+let includedZones = []
+if (argv.included_zones) {
var newZoneCfg = {}
- filteredZones.forEach((zoneName) => {
+ includedZones = argv.included_zones
+ includedZones.forEach((zoneName) => {
newZoneCfg[zoneName] = zoneCfg[zoneName]
})
zoneCfg = newZoneCfg
@@ -573,8 +587,8 @@
{ tzid: 'Etc/GMT+12', left: -180, right: -172.5 }
]
-if (filteredZones.length > 0) {
- oceanZones = oceanZones.filter(oceanZone => filteredZones.indexOf(oceanZone) > -1)
+if (includedZones.length > 0) {
+ oceanZones = oceanZones.filter(oceanZone => includedZones.indexOf(oceanZone) > -1)
}
var addOceans = function (callback) {
@@ -677,7 +691,7 @@
validateZones: ['createZones', function (results, cb) {
overallProgress.beginTask('Validating timezone boundaries')
loadDistZonesIntoMemory()
- if (process.argv.indexOf('no-validation') > -1) {
+ if (argv.no_validation) {
console.warn('WARNING: Skipping validation!')
cb()
} else {
@@ -728,8 +742,8 @@
oceanZones.forEach(oceanZone => {
zoneNames.push(oceanZone.tzid)
})
- if (filteredZones.length > 0) {
- zoneNames = zoneNames.filter(zoneName => filteredZones.indexOf(zoneName) > -1)
+ if (includedZones.length > 0) {
+ zoneNames = zoneNames.filter(zoneName => includedZones.indexOf(zoneName) > -1)
}
fs.writeFile(
'dist/timezone-names.json',