Skip to content

Commit

Permalink
Add support for --all to cli.js
Browse files Browse the repository at this point in the history
  • Loading branch information
pandrewhk committed Jun 16, 2015
1 parent 1dc5b18 commit b3092f8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
24 changes: 22 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function help() {
' -m, --min-length <number> minimum length to accept',
' -w, --whitelist <string> allow languages',
' -b, --blacklist <string> disallow languages',
' -a, --all display all guesses',
'',
'Usage:',
'',
Expand Down Expand Up @@ -77,6 +78,7 @@ var index;
var blacklist;
var whitelist;
var minLength;
var all = false;

/**
* Log the language for `value`.
Expand All @@ -85,11 +87,17 @@ var minLength;
*/
function detect(value) {
if (value && value.length) {
console.log(franc(value, {
var param = {
'minLength': minLength,
'whitelist': whitelist,
'blacklist': blacklist
}));
};
if (all) {
(franc.all(value, param))
.filter(function (a) { console.log(a[0] + ' ' + a[1]) } );
} else {
console.log(franc(value, param));
}
} else {
process.stderr.write(help());
process.exit(1);
Expand Down Expand Up @@ -147,6 +155,18 @@ if (
argv.splice(index, 2);
}

index = argv.indexOf('--all');

if (index === -1) {
index = argv.indexOf('-a');
}

if (index !== -1) {
all = true;

argv.splice(index, 1);
}

if (argv.length) {
detect(argv.join(' '));
} else if (!expextPipeIn) {
Expand Down
8 changes: 8 additions & 0 deletions test/cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ it "Should accept \`-m\`"
result=`./cli.js -m 4 "the"` 2> /dev/null
assert $result "und"

it "Should accept \`--all\`"
result=`./cli.js --all "Alle menslike wesens word vry" | grep afr | cut -f2 -d\ ` 2> /dev/null
assert $result 1

it "Should accept \`--a\`"
result=`./cli.js -a "Alle menslike wesens word vry" | grep afr | cut -f2 -d\ ` 2> /dev/null
assert $result 1

it "Should accept \`--help\`"
code=0
./cli.js --help > /dev/null 2>&1 || code=$?
Expand Down

0 comments on commit b3092f8

Please sign in to comment.