Skip to content

Commit

Permalink
Merge pull request #13 from pelias/move_cli
Browse files Browse the repository at this point in the history
move cli.js out of analyzer dir
  • Loading branch information
missinglink authored Jan 14, 2021
2 parents 28a220b + 3205690 commit 3844062
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 34 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,26 @@ there is an included CLI script which allows you to easily pipe in files for tes

```bash
# test a single input
$ node analyzer/cli.js en street <<< "n foo st w"
$ node cli.js en street <<< "n foo st w"

North Foo Street West

# test multiple inputs
$ echo -e "n foo st w\nw 16th st" | node analyzer/cli.js en street
$ echo -e "n foo st w\nw 16th st" | node cli.js en street

North Foo Street West
West 16 Street

# test against the contents of a file
$ node analyzer/cli.js en street < nyc.names
$ node cli.js en street < nyc.names

100 Avenue
100 Drive
100 Road
... etc

# test against openaddresses data
$ cut -d',' -f4 /data/oa/de/berlin.csv | sort | uniq | node analyzer/cli.js de street
$ cut -d',' -f4 /data/oa/de/berlin.csv | sort | uniq | node cli.js de street

Aachener Strasse
Aalemannufer
Expand All @@ -177,7 +177,7 @@ $ diff \
--width=100 \
--expand-tabs \
nyc.names \
<(node analyzer/cli.js en street < nyc.names)
<(node cli.js en street < nyc.names)

ZEBRA PL | Zebra Place
ZECK CT | Zeck Court
Expand Down
29 changes: 0 additions & 29 deletions analyzer/cli.js

This file was deleted.

26 changes: 26 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const readline = require('readline');
const tty = require('tty');

const locale = process.argv[2];
const analyzerName = process.argv.slice(3);

if (tty.isatty(process.stdin)) {
console.error('no data piped to stdin');
process.exit(1);
}

try {
const ctx = { locale: locale };
const analyzer = require('./analyzer/' + analyzerName).call(null, ctx);

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});

rl.on('line', line => console.log(analyzer(line)));
}
catch (e) {
console.error('invalid analyzer', analyzerName);
}

0 comments on commit 3844062

Please sign in to comment.