wikibase-cli 15.16.2 → 15.16.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/wb-hub CHANGED
@@ -3,9 +3,10 @@ const program = require('../lib/program')
3
3
 
4
4
  program
5
5
  .option('-o, --open', 'open the found URL in a web browser')
6
+ .option('-u, --url', 'simply generate the url')
6
7
  .process('hub')
7
8
 
8
- const { args, lang, json, open } = program
9
+ const { args, lang, json, open, url: urlOnly } = program
9
10
  if (args.length === 0) program.helpAndExit(0)
10
11
 
11
12
  let argsString = args.join(' ')
@@ -15,15 +16,15 @@ if (lang && !(/l(ang)?=/.test(argsString))) argsString += ` lang=${lang}`
15
16
  // Default to Wikidata instead of Wikipedia
16
17
  if (!(/s(ite)?=/.test(argsString))) argsString += ' site=wikidata'
17
18
 
18
- if (!open) argsString += ' format=json'
19
+ if (!(open || urlOnly)) argsString += ' format=json'
19
20
 
20
21
  const query = encodeURIComponent(argsString)
21
22
  const url = `https://tools.wmflabs.org/hub/query?q=${query}`
22
23
 
23
24
  const errors_ = require('../lib/errors')
24
25
 
25
- if (open) {
26
- require('open')(url, { url: true })
26
+ if (open || urlOnly) {
27
+ require('../lib/open')(url)
27
28
  } else {
28
29
  const output = require('../lib/output')(program)
29
30
  require('../lib/request').get(url)
package/bin/wd CHANGED
@@ -1,21 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- // This use to be a simple one line shell script, but due to
4
- // compatibility reasons with Windows, it needed to be rewritten
5
- // in the one environment we know is available: node
3
+ process.env.WB_INSTANCE = 'https://www.wikidata.org'
4
+ process.env.WB_SPARQL_ENDPOINT = 'https://query.wikidata.org/sparql'
5
+ // Fake the executed script to be wb to trick commander to believe it
6
+ // as it would otherwise fail to build subcommand paths
7
+ process.argv[1] = process.argv[1].replace(/wd$/, 'wb')
6
8
 
7
- const { spawn } = require('child_process')
8
-
9
- const escapeDollars = arg => arg.replace(/\$/g, '\\$')
10
- const args = process.argv.slice(2).map(escapeDollars)
11
-
12
- spawn('wb', args, {
13
- env: Object.assign({
14
- WB_INSTANCE: 'https://www.wikidata.org',
15
- WB_SPARQL_ENDPOINT: 'https://query.wikidata.org/sparql',
16
- }, process.env),
17
- stdio: 'inherit',
18
- // Required to not get a ENOENT on Windows
19
- // See https://stackoverflow.com/a/54515183/3324977
20
- shell: true,
21
- })
9
+ require('./wb')
@@ -1,6 +1,8 @@
1
1
  // Args can't be just a line splitted on spaces
2
2
  // as there are JSON strings arguments, and signle or double quoted strings args
3
3
 
4
+ const { parse } = require('shell-quote')
5
+
4
6
  module.exports = line => {
5
7
  // One JSON object as single argument
6
8
  // typically for (create|edit)-entity commands
@@ -11,7 +13,16 @@ module.exports = line => {
11
13
  // ex: [ "Q1" , "P2", '{"amount":123,"unit":"Q1947"}' ]'
12
14
  if (line[0] === '[') return JSON.parse(line)
13
15
 
14
- // Otherwise, arguments should be simple enough to be separated by a single space
15
- // ex: Q1 P2 123
16
- return line.split(' ')
16
+ // Otherwise, parse arguments as shell arguments
17
+ // ex: Q1 P2 "ab cd"
18
+ return parse(preserveDollarGuid(line))
19
+ }
20
+
21
+ const preserveDollarGuid = line => {
22
+ return line
23
+ // Dashed GUIDs should be a supported format and don't produce
24
+ // the same dollar issues when parsing as shell arguments
25
+ .replace(dollarGuidPattern, '$1-$2')
17
26
  }
27
+
28
+ const dollarGuidPattern = /(\w{1}\d+)\$([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/ig
package/metadata/hub.js CHANGED
@@ -13,6 +13,7 @@ module.exports = {
13
13
  examples: [
14
14
  { args: 'viaf:24597135', comment: 'Find the entity having 24597135 as VIAF id' },
15
15
  { args: '--open viaf:24597135 site=inventaire', comment: 'Find the entity having 24597135 as VIAF id and open the corresponding page on inventaire.io' },
16
- { args: 'Q3 property=image width=300', comment: 'Get the image illustrating Q3 in 300px' }
16
+ { args: 'Q3 property=image width=300', comment: 'Get the image illustrating Q3 in 300px' },
17
+ { args: 'Q3 --url', comment: 'Just return the query URL' },
17
18
  ]
18
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wikibase-cli",
3
- "version": "15.16.2",
3
+ "version": "15.16.6",
4
4
  "description": "A command-line interface to Wikibase",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -47,6 +47,7 @@
47
47
  "node-fetch": "^2.6.0",
48
48
  "open": "^7.0.4",
49
49
  "read": "^1.0.7",
50
+ "shell-quote": "^1.7.3",
50
51
  "split": "^1.0.1",
51
52
  "through": "^2.3.8",
52
53
  "wikibase-edit": "^4.16.0",