Closed nichtich closed 4 years ago
what would you think of simply using a JS file?
// item.js
module.exports = {
id: 'Q4115189',
labels: { nl: 'foo' }
}
wd edit-item ./item.js
we could then even export a function that could accept arguments:
// multilabel.js
module.exports = (id, label) => ({
id,
labels: { de: label, en: label, fr: label, nl: label }
})
wd edit-item ./multilabel.js Q2013 wikidata
Hey, the idea with optional arguments is great. I recommend a flag to preview the result (e.g. wd edit-item --dry ./multilabel.js Q2013 wikidata
could output the JSON result of require('./multilabel.js')("Q2013", "wikidata")
) and/or document recommended form of the input JSON files as:
#!/usr/bin/env node
module.exports = (id, label) => ({
id,
labels: { de: label, en: label, fr: label, nl: label }
})
if (require.main === module) {
let entity = module.exports(...process.argv.slice(2))
console.log(JSON.stringify(entity, null, 4))
}
I'd prefer not to require this kind of boilerplate code to just check back before actually doing an edit.
not to say that option shouldn't exist, but this can be done from command-line with a oneliner:
node -p "require('./multilabel.js')(...process.argv.slice(1))" Q2013 wikidata
Great, than including this line in the documentation should be enough.
I have been working on this JS template/function feature, if you want to try it, its on branch wd-edit-item-function
. I also implemented the --dry
option, as it was indeed convenient
I just published v7.3.0
, which includes dynamic JS templates \o/
Editing input files for
wd edit-item
andwd create-item
could be simplified by support of an HJSON as input format. Alternatives might be JSON5 and YAML.