Skip to content

Commit

Permalink
+ wd coord
Browse files Browse the repository at this point in the history
reimplementing the proposition made by nichtich #6
  • Loading branch information
maxlath committed Jan 28, 2017
1 parent ab3a441 commit c3281b0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ Options when passing both an id an property:
* `-c, --clipboard`: copy the result to clipboard
* `-j, --json`: format the result as JSON

#### wd coord
A command to output the geographic coordinates (latitude and longitude) of an entity

```sh
wd coord Q2112
# => 52.016666666667 8.5166666666667
```

#### wd data
A quick way to access an entities data
```sh
Expand Down
2 changes: 2 additions & 0 deletions bin/wd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const id = require('../configs/id')
const sparql = require('../configs/sparql')
const query = require('../configs/query')
const open = require('../configs/open')
const coord = require('../configs/coord')

program
.version(pkg.version)
Expand All @@ -22,4 +23,5 @@ program
.command(`sparql ${sparql.args}`, sparql.description)
.command(`query ${query.args}`, query.description)
.command(`open ${open.args}`, open.description)
.command(`coord ${coord.args}`, coord.description)
.parse(process.argv)
20 changes: 20 additions & 0 deletions bin/wd-coord
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)
10 changes: 10 additions & 0 deletions configs/coord.js
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' }
]
}
12 changes: 12 additions & 0 deletions test/wd-coord.js
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'))
})

0 comments on commit c3281b0

Please sign in to comment.