maxlath / wikibase-cli

read and edit a Wikibase instance from the command line
MIT License
226 stars 24 forks source link

Extend JS file templates with metadata #81

Closed nichtich closed 3 years ago

nichtich commented 4 years ago

As described here a JS file can be used as template. Option --dry emits the JSON data generated from the template, e.g.:

$ wd ei ./template.js Q1 abc 123 --dry

But how do I document the template to remember which parameters to pass to the template? How about supporting

$ wd ei ./template.js --help
Usage: wd ei ./template.js <id> <name> [quantity]
Adds some special statements.

By extension of the exported function with fields args and description:

module.exports = (id, name, quantity) => {
  return {
    id,
    claims: {
      P1449: name,
      ...(quantity ? { P1106: parseInt(quantity)} : {}) // optional
  }
}
module.exports.args = ['id', 'name', 'quantity?']
module.exports.description = "Adds some special statements."

Additional use of args (although I'm not sure whether array, object or string): wd can detect missing arguments and raise an error instead of passing bogus data to Wikibase backend.

The arguments might also depend on whether edit-item or create-item was used:

module.exports.args = {
  edit: ['id', 'name', 'quantity?'],
  create: ['id?', 'name', 'quantity?']
}

However the optionality of argument id as first argument may be a hard-coded best-practice instead.

maxlath commented 4 years ago

I gave it a shot here https://github.com/maxlath/wikibase-cli/pull/119 could you try to see if that works as you expected?

maxlath commented 4 years ago

However the optionality of argument id as first argument may be a hard-coded best-practice instead.

I just worked on a case where the initial input is a Wikipedia article url instead, and that looked rather like a nice possibility

maxlath commented 3 years ago

A first implementation of that template-specific help menu has been added in v15.4.0: template help menu

I'm thus closing this issue for now, but feel welcome to reopen it or open new ones for modifications of that feature