Commands generator for the update of json documents
This library provides some commands for manipulating a json configuration file. This configuration file must respect a json-schema.
Because json-commander is aware of the schema, it is able to provide a smart assistance which can be pretty handy if you are implementing a CLI.
You can find at the bottom of this documentation, an example using the commander package, but json-commander is not tied to any specific CLI library.
Install
$ npm install --save json-commanderUsage
var jsonCommander = ;var cmdr = ; var someJson = title: "Some title" contributors: name: "Olivier" name: "Aradhna" name: "Roy" ; cmdr; //will return AradhnaHelp
Display the help for the supported commands.
cmdr; //Will return some help All
Display the new configuration.
cmdr; //will return someJsonCheck
Check whether the configuration is valid or not.
cmdr; //will return valid or invalidCopy
Copy a value between two paths.
cmdr; //will replace Roy by olivierDel
Delete the value at the given path.
cmdr; //will delete RoyGet
Get the value at the given path.
cmdr; //will return "Some title"Insert
Insert a blank row.
cmdr; //will insert an empty contributor after AradhnaSet
Set the value at the given path.
cmdr; //Will replace 'Some title' by 'Much better title'Schema
Display the schema with all the possible paths.
cmdr; //Will display the schemaCreating a CLI
Json-commander can easily used to create a CLI.
Requires: commander solace confiture
The setup program:
;; const solace = ;const configurator = ; const setupProgram = { const hasOther = !_; const cmdOptions = hasOther ? cmd : cmd; const isWriting = cmd === 'set' || cmd === 'copy' || cmd === 'del' || cmd === 'insert'; if isWriting cmdr; configurator; solace; else const evaluation = cmdr; solace; };With commander to provide a CLI:
;program description'configure My CLI' actionsetupProgram;License
MIT © Olivier Huin