diff --git a/README.markdown b/README.markdown index 1f812bc..300c3a1 100644 --- a/README.markdown +++ b/README.markdown @@ -113,6 +113,23 @@ console.log(taxonomy(value)) // [ 'tier 1', 'numeric', 'non-redundant', 'flat' ] ``` +Usage (CLI) +----------- + +The published [npm](https://www.npmjs.com) package includes a simple +command-line interface program that can be globally installed as follows: + +```sh +npm install --global @sourcemeta/json-taxonomy +``` + +The CLI program takes the path to a JSON document as an argument and outputs +the taxonomy to standard output: + +```sh +json-taxonomy path/to/document.json +``` + License ------- diff --git a/js/cli.js b/js/cli.js new file mode 100644 index 0000000..bafae66 --- /dev/null +++ b/js/cli.js @@ -0,0 +1,17 @@ +#!/usr/bin/env node + +const fs = require('fs') +const taxonomy = require('..') +const INPUT = process.argv[2] + +if (!INPUT) { + console.error(`${process.argv[0]} ${process.argv[1]} `) + process.exit(1) +} + +fs.accessSync(INPUT, fs.constants.R_OK) +const value = JSON.parse(fs.readFileSync(INPUT, 'utf8')) + +console.log(taxonomy(value).map((qualifier) => { + return qualifier[0].toUpperCase() + qualifier.slice(1) +}).join(', ')) diff --git a/package-lock.json b/package-lock.json index c3344ee..e03bdb2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@sourcemeta/json-taxonomy", - "version": "1.0.1", + "version": "1.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 9d3959d..4c62254 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,11 @@ { "name": "@sourcemeta/json-taxonomy", - "version": "1.0.1", + "version": "1.1.0", "description": "A formal taxonomy to classify JSON documents based on their size, type of content, characteristics of their structure and redundancy criteria", "main": "js/index.js", + "bin": { + "json-taxonomy": "./js/cli.js" + }, "repository": { "type": "git", "url": "git+https://github.com/sourcemeta/json-taxonomy.git"