Skip to content

Commit

Permalink
Indentation, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
beaugunderson committed Dec 13, 2014
1 parent 20c897a commit 1319bc2
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 71 deletions.
48 changes: 24 additions & 24 deletions bin/ipv6.js
Expand Up @@ -13,28 +13,28 @@ var options = cli.parse();
var rows = [['Address', 'Valid', 'Correct Form', 'Canonical Form']];

cli.withStdinLines(function (lines) {
for (var i = 0; i < lines.length; i++) {
if (lines[i] === '') {
continue;
}

var address = new v6.Address(lines[i]);

if (options.v) {
this.output(sprintf('%s = %s\n', lines[i], cliff.inspect(address)));
} else if (options.c) {
rows.push([
lines[i],
address.isValid() ? 'Yes' : 'No'.red,
address.isValid() ? address.correctForm() : '',
address.isValid() ? address.canonicalForm() : ''
]);
} else {
this.output(sprintf('%s,%s\n', lines[i], address.isValid() ? 'valid' : 'invalid'));
}
}

if (options.c) {
console.log(cliff.stringifyRows(rows, ['green', 'green', 'green', 'green']));
}
for (var i = 0; i < lines.length; i++) {
if (lines[i] === '') {
continue;
}

var address = new v6.Address(lines[i]);

if (options.v) {
this.output(sprintf('%s = %s\n', lines[i], cliff.inspect(address)));
} else if (options.c) {
rows.push([
lines[i],
address.isValid() ? 'Yes' : 'No'.red,
address.isValid() ? address.correctForm() : '',
address.isValid() ? address.canonicalForm() : ''
]);
} else {
this.output(sprintf('%s,%s\n', lines[i], address.isValid() ? 'valid' : 'invalid'));
}
}

if (options.c) {
console.log(cliff.stringifyRows(rows, ['green', 'green', 'green', 'green']));
}
});
89 changes: 42 additions & 47 deletions bin/ipv6grep.js
Expand Up @@ -12,69 +12,64 @@ var v6 = require('..').v6;
cli.enable('version', 'status', 'glob');

cli.parse({
all: ['a', 'Find all addresses'],
validate: ['v', 'Validate found addresses'],
substring: ['s', 'Substring match']
all: ['a', 'Find all addresses'],
validate: ['v', 'Validate found addresses'],
substring: ['s', 'Substring match']
});

cli.debug('script: ' + process.argv[1]);

cli.main(function (args, options) {
cli.debug('args: ' + util.inspect(args));
cli.debug('options: ' + util.inspect(options));
cli.debug('args: ' + util.inspect(args));
cli.debug('options: ' + util.inspect(options));

var grepArguments = ['-P', '-i', '-n', '--color=always'];
var stdin = false;
var grepArguments = ['-P', '-i', '-n', '--color=always'];
var stdin = false;

var address;
var regex;
var address;
var regex;

if (args.length === 0 && options.all) {
// STDIN with all addresses
grepArguments.push('ADDRESS');
stdin = true;
} else if (args.length === 1) {
// STDIN
address = new v6.Address(new v6.Address(args[0]).correctForm());
regex = address.regularExpressionString(options.substring);
if (args.length === 0 && options.all) {
// STDIN with all addresses
grepArguments.push('ADDRESS');
stdin = true;
} else if (args.length === 1) {
// STDIN
address = new v6.Address(new v6.Address(args[0]).correctForm());
regex = address.regularExpressionString(options.substring);

cli.debug('address: ' + util.inspect(address.regularExpression()));
cli.debug('address: ' + util.inspect(address.regularExpression()));

grepArguments.push(regex);
stdin = true;
} else if (args.length > 1) {
// filename
address = new v6.Address(new v6.Address(args[0]).correctForm());
regex = address.regularExpressionString(options.substring);
grepArguments.push(regex);
stdin = true;
} else if (args.length > 1) {
// filename
address = new v6.Address(new v6.Address(args[0]).correctForm());
regex = address.regularExpressionString(options.substring);

var files = args.slice(1, args.length);
var files = args.slice(1, args.length);

cli.debug('address: ' + util.inspect(address.regularExpression()));
cli.debug('files: ' + util.inspect(files));
cli.debug('address: ' + util.inspect(address.regularExpression()));
cli.debug('files: ' + util.inspect(files));

grepArguments = grepArguments.concat(regex, files);
}
grepArguments = grepArguments.concat(regex, files);
}

cli.debug('grep arguments: ' + util.inspect(grepArguments));
cli.debug('grep arguments: ' + util.inspect(grepArguments));

if (!stdin) {
var grep = spawn('grep', grepArguments);
if (!stdin) {
var grep = spawn('grep', grepArguments);

grep.stdout.on('data', function (data) {
console.log(String(data).trim());
});
grep.stdout.on('data', function (data) {
console.log(String(data).trim());
});

grep.stderr.on('data', function (data) {
cli.debug(String(data).trim());
});
grep.stderr.on('data', function (data) {
cli.debug(String(data).trim());
});

grep.on('exit', function (code) {
cli.debug('grep exited: ' + code);
});

//grep.stdin.end();
}

//cli.withStdinLines(function(lines, newline) {
//});
grep.on('exit', function (code) {
cli.debug('grep exited: ' + code);
});
}
});

0 comments on commit 1319bc2

Please sign in to comment.