diff --git a/add-build.js b/add-build.js index f7c4d6e..50dd6fe 100644 --- a/add-build.js +++ b/add-build.js @@ -1,24 +1,26 @@ -var Troll = require('troll-opt').Troll; var models = require('./models/'); var fs = require('fs'); var utils = require('./utils.js'); -var buildInfo = (new Troll()).options(function(troll) { - troll.banner('Adds a new build to the database.'); - troll.opt('device', 'The device ID.', { type: 'string', required: true }); - troll.opt('timestamp', 'The build\'s timestamp as "unixepoch" timestamp ("ro.build.date.utc").', { type: 'integer', required: true }); - troll.opt('md5sum', 'The build\'s md5sum.', { type: 'string', required: true }); - troll.opt('filename', 'The resulting filename.', { type: 'string', required: true }); - troll.opt('channel', 'The update-channel.', { type: 'string', required: true }); - troll.opt('api_level', 'The SDK API-level of the ROM ("ro.build.version.sdk").', { type: 'integer', required: true }); - troll.opt('subdirectory', 'The subdirectory from which the file can be downloaded.', { type: 'string' }); - troll.opt('active', 'Marks the build as active (available for download) or not.', { type: 'boolean', required: true }); - troll.opt('sourcecode_timestamp', 'The ("unixepoch") timestamp when the source code was updated.', { type: 'integer' }); - troll.opt('filesize', 'The size (in bytes) of the ZIP file.', { type: 'integer' }); - troll.opt('incrementalid', 'The build\s incremental ID ("ro.build.version.incremental").', { type: 'string' }); - troll.opt('changelogfile', 'A path to a file which contains the changelog (utf-8 encoded) for the build.', { type: 'string' }); - troll.opt('targetfileszip', 'The name of the "target files" ZIP archive (useful for generating incremental updates).', { type: 'string' }); -}); +var buildInfo = require('yargs') + .usage('Usage: $0 [options]\n Adds a new build to the database.') + .alias('active', 'A').boolean('active').describe('active', 'Marks the build as active (available for download) or not.') + .alias('api_level', 'a').nargs('api_level', 1).number('api_level').describe('api_level', 'The SDK API-level of the ROM ("ro.build.version.sdk").') + .alias('changelogfile', 'C').nargs('changelogfile', 1).describe('changelogfile', 'A path to a file which contains the changelog (utf-8 encoded) for the build.') + .alias('channel', 'c').nargs('channel', 1).describe('channel', 'The update-channel.') + .alias('device', 'd').nargs('device', 1).describe('device', 'The device ID.') + .alias('filename', 'f').nargs('filename', 1).describe('filename', 'The resulting filename.') + .alias('filesize', 'F').nargs('filesize', 1).number('filesize').describe('filesize', 'The size (in bytes) of the ZIP file.') + .alias('incrementalid', 'i').nargs('incrementalid', 1).describe('incrementalid', 'The build\'s incremental ID ("ro.build.version.incremental").') + .alias('md5sum', 'm').nargs('md5sum', 1).describe('md5sum', 'The build\'s md5sum.') + .alias('subdirectory', 's').nargs('subdirectory', 1).describe('subdirectory', 'The subdirectory from which the file can be downloaded.') + .alias('sourcecode_timestamp', 'S').nargs('sourcecode_timestamp', 1).number('sourcecode_timestamp').describe('sourcecode_timestamp', 'The ("unixepoch") timestamp when the source code was updated.') + .alias('targetfileszip', 'T').nargs('targetfileszip', 1).describe('targetfileszip', 'The name of the "target files" ZIP archive (useful for generating incremental updates).') + .alias('timestamp', 't').nargs('timestamp', 1).number('timestamp').describe('timestamp', 'The build\'s timestamp as "unixepoch" timestamp ("ro.build.date.utc").') + .demandOption(['api_level', 'active', 'channel', 'device', 'filename', 'md5sum', 'timestamp']) + .help('help').alias('help', 'h') + .argv; + function createNewRomVariantFor(device) { var variantName = device.name + '_' + new Date().getTime(); diff --git a/add-incremental.js b/add-incremental.js index bdad572..2dc8e51 100644 --- a/add-incremental.js +++ b/add-incremental.js @@ -1,19 +1,20 @@ -var Troll = require('troll-opt').Troll; var models = require('./models/'); var fs = require('fs'); var utils = require('./utils.js'); -var buildInfo = (new Troll()).options(function(troll) { - troll.banner('Adds a new incremental build to the database.'); - troll.opt('timestamp', 'The build\'s timestamp as "unixepoch" timestamp ("ro.build.date.utc").', { type: 'integer', required: true }); - troll.opt('md5sum', 'The build\'s md5sum.', { type: 'string', required: true }); - troll.opt('filename', 'The resulting filename.', { type: 'string', required: true }); - troll.opt('subdirectory', 'The subdirectory from which the file can be downloaded.', { type: 'string' }); - troll.opt('from_target_files', 'The name of the "target files ZIP" of the incremental\'s "source".', { type: 'string', required: true }); - troll.opt('to_target_files', 'The name of the "target files ZIP" of the incremental\'s "target".', { type: 'string', required: true }); - troll.opt('active', 'Marks the incremental as active (available for download) or not.', { type: 'boolean', required: true }); - troll.opt('filesize', 'The size (in bytes) of the incremental update file.', { type: 'integer' }); -}); +var buildInfo = require('yargs') + .usage('Usage: $0 [options]\n Adds a new incremental build to the database.') + .alias('active', 'a').boolean('active').describe('active', 'Marks the incremental as active (available for download) or not.') + .alias('filename', 'f').nargs('filename', 1).describe('filename', 'The resulting filename.') + .alias('filesize', 'i').nargs('filesize', 1).number('filesize').describe('filesize', 'The size (in bytes) of the incremental update file.') + .alias('from_target_files', 'F').nargs('from_target_files', 1).describe('from_target_files', 'The name of the "target files ZIP" of the incremental\'s "source".') + .alias('md5sum', 'm').nargs('md5sum', 1).describe('md5sum', 'The build\'s md5sum.') + .alias('subdirectory', 's').nargs('subdirectory', 1).describe('subdirectory', 'The subdirectory from which the file can be downloaded.') + .alias('timestamp', 't').nargs('timestamp', 1).number('timestamp').describe('timestamp', 'The build\'s timestamp as "unixepoch" timestamp ("ro.build.date.utc").') + .alias('to_target_files', 'T').nargs('to_target_files', 1).describe('to_target_files', 'The name of the "target files ZIP" of the incremental\'s "target".') + .demandOption(['active', 'device', 'filename', 'from_target_files', 'md5sum', 'timestamp', 'to_target_files']) + .help('help').alias('help', 'h') + .argv; function createNewIncremental(sourceRom, targetRom) { var buildTimestamp = utils.toDate(buildInfo.timestamp); diff --git a/disable-build.js b/disable-build.js index 13a358b..50a7e7e 100644 --- a/disable-build.js +++ b/disable-build.js @@ -1,14 +1,15 @@ -var Troll = require('troll-opt').Troll; var models = require('./models/'); var utils = require('./utils.js'); -var buildInfo = (new Troll()).options(function(troll) { - troll.banner('Marks a build as disabled so it cannot be downloaded anymore.'); - troll.opt('device', 'The device ID.', { type: 'string', required: true }); - troll.opt('filename', 'The resulting filename.', { type: 'string', required: true }); - troll.opt('subdirectory', 'The subdirectory from which the file can be downloaded.', { type: 'string' }); - troll.opt('disable_incrementals', 'Disables the incrementals for this rom also.', { type: 'boolean' }); -}); +var buildInfo = require('yargs') + .usage('Usage: $0 [options]\n Marks a build as disabled so it cannot be downloaded anymore.') + .alias('device', 'd').nargs('device', 1).describe('device', 'The device ID.') + .alias('disable_incrementals', 'D').boolean('disable_incrementals').describe('disable_incrementals', 'Disables the incrementals for this rom also.') + .alias('filename', 'f').nargs('filename', 1).describe('filename', 'The resulting filename.') + .alias('subdirectory', 's').nargs('subdirectory', 1).describe('subdirectory', 'The subdirectory from which the file can be downloaded.') + .demandOption(['device', 'filename']) + .help('help').alias('help', 'h') + .argv; utils.rethrowUnhandledPromiseRejections(); diff --git a/get-sourcecode-timestamp.js b/get-sourcecode-timestamp.js index e7fa6e7..7b5d77f 100644 --- a/get-sourcecode-timestamp.js +++ b/get-sourcecode-timestamp.js @@ -1,12 +1,13 @@ -var Troll = require('troll-opt').Troll; var models = require('./models/'); var utils = require('./utils.js'); -var buildInfo = (new Troll()).options(function(troll) { - troll.banner('Outputs the newest source-code as ISO-8601 string for the given device / subdirectory.'); - troll.opt('device', 'The device ID.', { type: 'string', required: true }); - troll.opt('subdirectory', 'The subdirectory from which the file can be downloaded.', { type: 'string' }); -}); +var buildInfo = require('yargs') + .usage('Usage: $0 [options]\n Outputs the newest source-code as ISO-8601 string for the given device / subdirectory.') + .alias('device', 'd').nargs('device', 1).describe('device', 'The device ID.') + .alias('subdirectory', 's').nargs('subdirectory', 1).describe('subdirectory', 'The subdirectory from which the file can be downloaded.') + .demandOption(['device']) + .help('help').alias('help', 'h') + .argv; utils.rethrowUnhandledPromiseRejections(); diff --git a/get-target-file-zipnames.js b/get-target-file-zipnames.js index cd3c0e5..a956cc7 100644 --- a/get-target-file-zipnames.js +++ b/get-target-file-zipnames.js @@ -1,13 +1,15 @@ -var Troll = require('troll-opt').Troll; var models = require('./models/'); var utils = require('./utils.js'); -var buildInfo = (new Troll()).options(function(troll) { - troll.banner('Outputs all target-files zip names (one per line) for all builds that match the given device / subdirectory.'); - troll.opt('device', 'The device ID.', { type: 'string', required: true }); - troll.opt('subdirectory', 'The subdirectory from which the file can be downloaded.', { type: 'string' }); - troll.opt('max_age_days', 'The max age (according to a Rom\' timestamp) of the target files in days.', { type: 'integer' }); -}); +var buildInfo = require('yargs') + .usage('Usage: $0 [options]\n Outputs all target-files zip names (one per line) for all builds that match the given device / subdirectory.') + .alias('device', 'd').nargs('device', 1).describe('device', 'The device ID.') + .alias('max_age_days', 'max_age_days').nargs('max_age_days', 1).number('max_age_days').describe('max_age_days', 'The max age (according to a Rom\'s timestamp) of the target files in days.') + .alias('subdirectory', 's').nargs('subdirectory', 1).describe('subdirectory', 'The subdirectory from which the file can be downloaded.') + .demandOption(['device']) + .help('help').alias('help', 'h') + .argv; + var minDate = new Date(-8640000000000000); diff --git a/package.json b/package.json index 58682be..f46b126 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ }, "dependencies": { - "troll-opt" : "^0.7.0", + "yargs" : "^6.6.0", "config": "^1.24.0", "restify": "^4.2.0", "sequelize-cli": "^2.4.0",