wikibase-cli 16.0.0 → 16.1.0

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/README.md CHANGED
@@ -54,7 +54,7 @@ See [CHANGELOG.md](CHANGELOG.md) for version info
54
54
  ## Dependencies
55
55
 
56
56
  ### General
57
- * [NodeJs](https://nodejs.org) **>= v8** (recommended way to install it: use the awesome [NVM](https://github.com/creationix/nvm))
57
+ * [NodeJs](https://nodejs.org) **>= v10** (recommended way to install it: use the awesome [NVM](https://github.com/creationix/nvm) to install the latest LTS version `nvm install --lts`)
58
58
  * [Git](https://git-scm.com/)
59
59
 
60
60
  ### Per feature
package/bin/wb-add-claim CHANGED
@@ -7,4 +7,5 @@ const inlineArgsParser = ([ id, property, value ]) => {
7
7
  return [ data ]
8
8
  }
9
9
  program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
10
+ program.customHelpOption = require('../lib/command_with_template_custom_help')
10
11
  require('../lib/edit/edit_command')('claim', 'add')
@@ -1,7 +1,24 @@
1
1
  #!/usr/bin/env node
2
2
  const program = require('commander')
3
3
  const polymorphicCommandArgsParser = require('../lib/polymorphic_command_args_parser')
4
- const inlineArgsParser = args => [ { from: args[0], to: args[1] } ]
4
+
5
+ const inlineArgsParser = args => {
6
+ if (program.keepOldest) {
7
+ const [ newest, oldest ] = getSortedEntitiesIds(args)
8
+ return [ { from: newest, to: oldest } ]
9
+ } else {
10
+ return [ { from: args[0], to: args[1] } ]
11
+ }
12
+ }
13
+
14
+ const getSortedEntitiesIds = args => {
15
+ return args
16
+ .slice(0, 2)
17
+ .sort((a, b) => getNumericId(b) - getNumericId(a))
18
+ }
19
+
20
+ const getNumericId = id => parseInt(id.replace(/^[A-Z]+/i, ''))
21
+
5
22
  program.customArgsParser = polymorphicCommandArgsParser(inlineArgsParser)
6
23
  program.customHelpOption = require('../lib/command_with_template_custom_help')
7
24
  require('../lib/edit/edit_command')('entity', 'merge')
package/bin/wb-search CHANGED
@@ -15,6 +15,7 @@ if (!(search && search.length > 0)) program.helpAndExit(0)
15
15
 
16
16
  let { lang: language, json, verbose, properties, limit, type, cirrus } = program
17
17
  limit = limit || 20
18
+ if (typeof limit === 'string') limit = parseInt(limit)
18
19
 
19
20
  if (properties) program.verbose = verbose = true
20
21
 
@@ -152,7 +152,7 @@ const runInBatch = (section, action, exitOnError) => {
152
152
  successes++
153
153
  } catch (err) {
154
154
  errors++
155
- if (exitOnError) throw err
155
+ if (exitOnError) logErrorAndExit(err)
156
156
  else if (err.code === 'EMPTY_PARAMS') console.error('produced an empty parameters object: passing')
157
157
  else console.error(`error triggered by line: "${line}":`, err)
158
158
  }
@@ -175,6 +175,10 @@ const randomKey = () => Math.random().toString(16).slice(2)
175
175
  const logErrorAndExit = err => {
176
176
  if (err.statusCode === 400) {
177
177
  console.error(red(err.message), err.context)
178
+ } else if (err.body && err.body.error && err.body.error.messages) {
179
+ err.body.error.messages.forEach(message => {
180
+ console.error(`${red(message.name)}\n${JSON.stringify(message, null, 2)}`)
181
+ })
178
182
  } else {
179
183
  // util.inspect doc: https://nodejs.org/api/util.html#util_util_inspect_object_options
180
184
  console.error(inspect(err, { depth: null, maxArrayLength: null }))
@@ -11,5 +11,6 @@ module.exports = {
11
11
  summary: [ '-s, --summary <text>', 'set the edit summary' ],
12
12
  baserevid: [ '--baserevid <id>', 'set the baserevid' ],
13
13
  maxlag: [ '--maxlag <num>', 'set the maxlag value' ],
14
- rank: [ '--rank <rank>', 'set the claim rank' ]
14
+ rank: [ '--rank <rank>', 'set the claim rank' ],
15
+ keepOldest: [ '--keep-oldest', 'Merge the newest entity in the oldest one. By default, the arguments order determins which entity is kept: the first entity is merged into the second entity' ],
15
16
  }
@@ -4,7 +4,7 @@ module.exports = {
4
4
  alias: 'me',
5
5
  args: '<from-id> <to-id>',
6
6
  description: 'Merge an entity into another',
7
- options: editCommands,
7
+ options: { keepOldest: true, ...editCommands },
8
8
  examples: [
9
9
  {
10
10
  args: 'Q1 Q2',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wikibase-cli",
3
- "version": "16.0.0",
3
+ "version": "16.1.0",
4
4
  "description": "A command-line interface to Wikibase",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -50,7 +50,7 @@
50
50
  "shell-quote": "^1.7.3",
51
51
  "split": "^1.0.1",
52
52
  "through": "^2.3.8",
53
- "wikibase-edit": "^5.0.0",
53
+ "wikibase-edit": "^5.0.3",
54
54
  "wikibase-sdk": "^8.0.0",
55
55
  "wikidata-lang": "^2.0.11"
56
56
  },