-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reimplementing the proposition made by nichtich #6
- Loading branch information
Showing
5 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env node | ||
// wd-coord is a simple alias of wd claims with the property set to P625 | ||
|
||
const program = require('../lib/program') | ||
program.process('coord') | ||
if (program.args.length === 0) return program.help() | ||
|
||
const execa = require('execa') | ||
// Use the raw args to let wd claims re-parse the options | ||
const args = program.rawArgs.slice(2).join(' ') | ||
// Whatever the arguments, inject the property P625 just after | ||
// whatever is likely to be parsed as a Qid | ||
.replace(/(Q\d+[^\s]*)/, '$1 P625') | ||
|
||
// Sub shell seem to disable chalk colors unless passed FORCE_COLOR | ||
const env = 'export FORCE_COLOR=true' | ||
|
||
execa.shell(`${env}; ./bin/wd claims ${args}`) | ||
.then(res => console.log(res.stdout)) | ||
.catch(console.error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
args: '<entity>', | ||
options: { | ||
lang: false | ||
}, | ||
description: 'display the geographic coordinates (latitude and longitude) of an entity (P625)', | ||
examples: [ | ||
{ args: 'Q456', comment: 'fetch the coordinates of the city of Lyon' } | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const test = require('ava') | ||
const execa = require('execa') | ||
|
||
test('wd coord: display help', t => { | ||
return execa.shell('../bin/wd claims') | ||
.then(res => t.is(res.stdout.split('Usage:').length, 2)) | ||
}) | ||
|
||
test('wd coord <id>', t => { | ||
return execa.shell('../bin/wd claims Q90 P625') | ||
.then(res => t.is(res.stdout, '48.856577777778 2.3518277777778')) | ||
}) |