Permalink
Browse files

Added verbosity level by number of lines to print out.

  • Loading branch information...
1 parent 2c67b33 commit 09a1c580243c71913754d4734f9c1c1e32f3f5b3 Amit Apple committed Jan 4, 2013
Showing with 51 additions and 9 deletions.
  1. +23 −4 bin/kuduSync.js
  2. +1 −1 lib/Header.ts
  3. +27 −4 lib/Main.ts
View
@@ -475,25 +475,44 @@ function kuduSyncDirectory(from, to, fromRootPath, toRootPath, manifest, outMani
}
function main() {
var commander = require("commander");
- commander.version("0.0.1").usage("[options]").option("-f, --fromDir <dir path>", "Source directory to sync").option("-t, --toDir <dir path>", "Destination directory to sync").option("-n, --nextManifest <manifest file path>", "Next manifest file path").option("-p, --previousManifest [manifest file path]", "Previous manifest file path").option("-i, --ignore [patterns]", "List of files/directories to ignore and not sync, delimited by ;").option("-q, --quiet", "No logging").option("-w, --whatIf", "Only log without actual copy/remove of files").parse(process.argv);
+ commander.version("0.0.1").usage("[options]").option("-f, --fromDir <dir path>", "Source directory to sync").option("-t, --toDir <dir path>", "Destination directory to sync").option("-n, --nextManifest <manifest file path>", "Next manifest file path").option("-p, --previousManifest [manifest file path]", "Previous manifest file path").option("-i, --ignore [patterns]", "List of files/directories to ignore and not sync, delimited by ;").option("-q, --quiet", "No logging").option("-v, --verbose [maxLines]", "Verbose logging with maximum number of output lines").option("-w, --whatIf", "Only log without actual copy/remove of files").parse(process.argv);
var commanderValues = commander;
var fromDir = commanderValues.fromDir;
var toDir = commanderValues.toDir;
var previousManifest = commanderValues.previousManifest;
var nextManifest = commanderValues.nextManifest;
var ignore = commanderValues.ignore;
var quiet = commanderValues.quiet;
+ var verbose = commanderValues.verbose;
var whatIf = commanderValues.whatIf;
- if(quiet) {
- log = function () {
- };
+ if(quiet && verbose) {
+ console.log("Error: Cannot use --quiet and --verbose arguments together");
+ process.exit(1);
+ return;
}
if(!fromDir || !toDir || !nextManifest) {
console.log("Error: Missing required argument");
commander.help();
process.exit(1);
return;
}
+ if(quiet) {
+ log = function () {
+ };
+ }
+ var counter = 0;
+ if(verbose && verbose > 0) {
+ log = function (msg) {
+ if(counter < verbose) {
+ console.log(msg);
+ } else {
+ if(counter == verbose) {
+ console.log("Omitting next output lines...");
+ }
+ }
+ counter++;
+ };
+ }
kuduSync(fromDir, toDir, nextManifest, previousManifest, ignore, whatIf).then(function () {
process.exit(0);
}, function (err) {
View
@@ -7,7 +7,7 @@ var pathUtil = require('path');
var Q = require('q');
var minimatch = require('minimatch');
-var log = console.log;
+var log: any = console.log;
// Workaround to support both APIs whether in node 0.6.* or 0.8.0 and higher.
if (!fs.existsSync) fs.existsSync = pathUtil.existsSync;
View
@@ -1,7 +1,6 @@
///<reference path='fileUtils.ts'/>
///<reference path='../typings/commander.d.ts'/>
-
function main() {
var commander: Commander = require("commander");
@@ -14,6 +13,7 @@ function main() {
.option("-p, --previousManifest [manifest file path]", "Previous manifest file path")
.option("-i, --ignore [patterns]", "List of files/directories to ignore and not sync, delimited by ;")
.option("-q, --quiet", "No logging")
+ .option("-v, --verbose [maxLines]", "Verbose logging with maximum number of output lines")
.option("-w, --whatIf", "Only log without actual copy/remove of files")
.parse(process.argv);
@@ -24,11 +24,16 @@ function main() {
var nextManifest = commanderValues.nextManifest;
var ignore = commanderValues.ignore;
var quiet = commanderValues.quiet;
+ var verbose = commanderValues.verbose;
var whatIf = commanderValues.whatIf;
- if (quiet) {
- // Change log to be no op
- log = () => { };
+ if (quiet && verbose) {
+ console.log("Error: Cannot use --quiet and --verbose arguments together");
+
+ // Exit with an error code
+ process.exit(1);
+
+ return;
}
if (!fromDir || !toDir || !nextManifest) {
@@ -41,6 +46,24 @@ function main() {
return;
}
+ if (quiet) {
+ // Change log to be no op
+ log = () => { };
+ }
+
+ var counter = 0;
+ if (verbose && verbose > 0) {
+ log = (msg) => {
+ if (counter < verbose) {
+ console.log(msg);
+ }
+ else if (counter == verbose) {
+ console.log("Omitting next output lines...");
+ }
+ counter++;
+ };
+ }
+
kuduSync(
fromDir,
toDir,

0 comments on commit 09a1c58

Please sign in to comment.