Skip to content

Commit f15b3dd

Browse files
committed
Implement a basic CLI
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent b7781ba commit f15b3dd

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

README.markdown

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,23 @@ console.log(taxonomy(value))
113113
// [ 'tier 1', 'numeric', 'non-redundant', 'flat' ]
114114
```
115115

116+
Usage (CLI)
117+
-----------
118+
119+
The published [npm](https://www.npmjs.com) package includes a simple
120+
command-line interface program that can be globally installed as follows:
121+
122+
```sh
123+
npm install --global @sourcemeta/json-taxonomy
124+
```
125+
126+
The CLI program takes the path to a JSON document as an argument and outputs
127+
the taxonomy to standard output:
128+
129+
```sh
130+
json-taxonomy path/to/document.json
131+
```
132+
116133
License
117134
-------
118135

js/cli.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs')
4+
const taxonomy = require('..')
5+
const INPUT = process.argv[2]
6+
7+
if (!INPUT) {
8+
console.error(`${process.argv[0]} ${process.argv[1]} <document.json>`)
9+
process.exit(1)
10+
}
11+
12+
fs.accessSync(INPUT, fs.constants.R_OK)
13+
const value = JSON.parse(fs.readFileSync(INPUT, 'utf8'))
14+
15+
console.log(taxonomy(value).map((qualifier) => {
16+
return qualifier[0].toUpperCase() + qualifier.slice(1)
17+
}).join(', '))

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
22
"name": "@sourcemeta/json-taxonomy",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "A formal taxonomy to classify JSON documents based on their size, type of content, characteristics of their structure and redundancy criteria",
55
"main": "js/index.js",
6+
"bin": {
7+
"json-taxonomy": "./js/cli.js"
8+
},
69
"repository": {
710
"type": "git",
811
"url": "git+https://github.com/sourcemeta/json-taxonomy.git"

0 commit comments

Comments
 (0)