Skip to content

Commit 780f9a5

Browse files
committed
Switch from nomnom to commander
1 parent 1c3adec commit 780f9a5

File tree

3 files changed

+55
-114
lines changed

3 files changed

+55
-114
lines changed

cli.js

Lines changed: 42 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,37 @@
11
#!/usr/bin/env node
22
/* eslint no-console: "off" */
3-
const os = require('os');
4-
const nomnom = require('nomnom');
5-
const puppetdbquery = require('./main');
6-
const querystring = require('querystring');
7-
const fs = require('fs');
8-
const http = require('http');
9-
const https = require('https');
3+
const os = require("os");
4+
const commander = require("commander");
5+
const puppetdbquery = require("./main");
6+
const querystring = require("querystring");
7+
const fs = require("fs");
8+
const http = require("http");
9+
const https = require("https");
1010

11-
const getCommandlineOptions = () => {
12-
const opts = nomnom.script('find-nodes')
13-
.option('host', {
14-
abbr: 'H',
15-
default: 'puppetdb',
16-
metavar: 'HOST',
17-
help: 'PuppetDB host',
18-
})
19-
.option('port', {
20-
abbr: 'p',
21-
default: 8080,
22-
metavar: 'PORT',
23-
help: 'PuppetDB port',
24-
callback(port) {
25-
return parseInt(port, 10);
26-
},
27-
})
28-
.option('ssl', {
29-
abbr: 's',
30-
flag: true,
31-
default: false,
32-
help: 'Use SSL',
33-
})
34-
.option('key', {
35-
default: `/etc/puppet/ssl/private_keys/${os.hostname()}.pem`,
36-
metavar: 'KEY',
37-
help: 'Private SSL key file',
38-
})
39-
.option('cert', {
40-
default: `/etc/puppet/ssl/certs/${os.hostname()}.pem`,
41-
metavar: 'CERT',
42-
help: 'SSL certificate file',
43-
})
44-
.option('ca', {
45-
default: '/etc/puppet/ssl/ca.pem',
46-
metavar: 'CACERT',
47-
help: 'SSL CA certificate file',
48-
})
49-
.option('version', {
50-
abbr: 'v',
51-
flag: true,
52-
help: 'print version and exit',
53-
callback() {
54-
return process.env.npm_package_version;
55-
},
56-
})
57-
.option('print', {
58-
abbr: 'P',
59-
flag: true,
60-
default: false,
61-
help: 'Print parsed query and exit',
62-
})
63-
.option('query', {
64-
flag: true,
65-
required: true,
66-
position: 0,
67-
help: 'query string',
68-
})
69-
.parse();
70-
return opts;
71-
};
11+
const opts = commander
12+
.command("find-nodes [options] <query>")
13+
.option("-H, --host <host>", "PuppetDB host")
14+
.option("-p, --port <port>", "PuppetDB port", 8080)
15+
.option("-s, --ssl", "Use SSL")
16+
.option(
17+
"--key <keyfile>",
18+
"Private SSL key file",
19+
`/etc/puppet/ssl/private_keys/${os.hostname()}.pem`
20+
)
21+
.option(
22+
"--cert <certfile>",
23+
"SSL certificate file",
24+
`/etc/puppet/ssl/certs/${os.hostname()}.pem`
25+
)
26+
.option("--ca <cafile>", "SSL CA certificate file", "/etc/puppet/ssl/ca.pem")
27+
.option("-P, --print", "Print parsed query and exit")
28+
.parse(process.argv);
7229

73-
const opts = getCommandlineOptions();
7430
let query;
7531
try {
76-
query = JSON.stringify(puppetdbquery.parse(opts.query));
32+
query = JSON.stringify(puppetdbquery.parse(opts.args[0]));
7733
} catch (err) {
34+
console.log(opts);
7835
console.log(err);
7936
}
8037

@@ -88,8 +45,8 @@ if (opts.print) {
8845
port: opts.port,
8946
path: `/pdb/query/v4/nodes?${querystring.stringify({ query })}`,
9047
headers: {
91-
Accept: 'application/json',
92-
},
48+
Accept: "application/json"
49+
}
9350
};
9451
let httplib;
9552
if (opts.ssl) {
@@ -102,14 +59,19 @@ if (opts.print) {
10259
}
10360

10461
// We have the full response, parse it and print the node names
105-
httplib.get(options, (res) => {
106-
let data = '';
107-
res.on('data', (chunk) => { data += chunk; });
62+
httplib
63+
.get(options, res => {
64+
let data = "";
65+
res.on("data", chunk => {
66+
data += chunk;
67+
});
10868

109-
return res.on('end', () =>
110-
JSON.parse(data).forEach(node => console.log(node.certname))
111-
);
112-
})
69+
return res.on("end", () =>
70+
JSON.parse(data).forEach(node => console.log(node.certname))
71+
);
72+
})
11373

114-
.on('error', e => console.log(`Error fetching from ${opts.host} : ${opts.port} ${e}`));
74+
.on("error", e =>
75+
console.log(`Error fetching from ${opts.host} : ${opts.port} ${e}`)
76+
);
11577
}

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-puppetdbquery",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"description": "a simple query language parser for PuppetDB v4 API",
55
"main": "main",
66
"bin": {
@@ -16,7 +16,13 @@
1616
"type": "git",
1717
"url": "https://github.com/dalen/node-puppetdbquery.git"
1818
},
19-
"keywords": ["puppetdb", "query", "puppetdbquery", "puppet", "jison"],
19+
"keywords": [
20+
"puppetdb",
21+
"query",
22+
"puppetdbquery",
23+
"puppet",
24+
"jison"
25+
],
2026
"author": "Erik Dalén <erik.gustav.dalen@gmail.com>",
2127
"license": "Apache-2.0",
2228
"bugs": {
@@ -25,7 +31,7 @@
2531
"homepage": "https://github.com/dalen/node-puppetdbquery",
2632
"dependencies": {
2733
"ast-types": "^0.8.18",
28-
"nomnom": "^1.6.0",
34+
"commander": "^2.15.1",
2935
"timespec": "^0.3.0"
3036
},
3137
"devDependencies": {

yarn.lock

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ ansi-styles@^3.1.0:
9191
dependencies:
9292
color-convert "^1.9.0"
9393

94-
ansi-styles@~1.0.0:
95-
version "1.0.0"
96-
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-1.0.0.tgz#cb102df1c56f5123eab8b67cd7b98027a0279178"
97-
9894
anymatch@^1.3.0:
9995
version "1.3.2"
10096
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-1.3.2.tgz#553dcb8f91e3c889845dfdba34c77721b90b9d7a"
@@ -832,14 +828,6 @@ chalk@^2.0.0, chalk@^2.1.0:
832828
escape-string-regexp "^1.0.5"
833829
supports-color "^4.0.0"
834830

835-
chalk@~0.4.0:
836-
version "0.4.0"
837-
resolved "https://registry.yarnpkg.com/chalk/-/chalk-0.4.0.tgz#5199a3ddcd0c1efe23bc08c1b027b06176e0c64f"
838-
dependencies:
839-
ansi-styles "~1.0.0"
840-
has-color "~0.1.0"
841-
strip-ansi "~0.1.0"
842-
843831
chokidar@^1.0.0:
844832
version "1.7.0"
845833
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.7.0.tgz#798e689778151c8076b4b360e5edd28cda2bb468"
@@ -947,6 +935,10 @@ combined-stream@^1.0.5, combined-stream@~1.0.5:
947935
dependencies:
948936
delayed-stream "~1.0.0"
949937

938+
commander@^2.15.1:
939+
version "2.15.1"
940+
resolved "https://registry.yarnpkg.com/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f"
941+
950942
commander@^2.9.0:
951943
version "2.11.0"
952944
resolved "https://registry.yarnpkg.com/commander/-/commander-2.11.0.tgz#157152fd1e7a6c8d98a5b715cf376df928004563"
@@ -1725,10 +1717,6 @@ has-ansi@^2.0.0:
17251717
dependencies:
17261718
ansi-regex "^2.0.0"
17271719

1728-
has-color@~0.1.0:
1729-
version "0.1.7"
1730-
resolved "https://registry.yarnpkg.com/has-color/-/has-color-0.1.7.tgz#67144a5260c34fc3cca677d041daf52fe7b78b2f"
1731-
17321720
has-flag@^1.0.0:
17331721
version "1.0.0"
17341722
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-1.0.0.tgz#9d9e793165ce017a00f00418c43f942a7b1d11fa"
@@ -2588,13 +2576,6 @@ nomnom@1.5.2, "nomnom@>= 1.5.x":
25882576
colors "0.5.x"
25892577
underscore "1.1.x"
25902578

2591-
nomnom@^1.6.0:
2592-
version "1.8.1"
2593-
resolved "https://registry.yarnpkg.com/nomnom/-/nomnom-1.8.1.tgz#2151f722472ba79e50a76fc125bb8c8f2e4dc2a7"
2594-
dependencies:
2595-
chalk "~0.4.0"
2596-
underscore "~1.6.0"
2597-
25982579
nopt@^4.0.1:
25992580
version "4.0.1"
26002581
resolved "https://registry.yarnpkg.com/nopt/-/nopt-4.0.1.tgz#d0d4685afd5415193c8c7505602d0d17cd64474d"
@@ -3514,10 +3495,6 @@ strip-ansi@^4.0.0:
35143495
dependencies:
35153496
ansi-regex "^3.0.0"
35163497

3517-
strip-ansi@~0.1.0:
3518-
version "0.1.1"
3519-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-0.1.1.tgz#39e8a98d044d150660abe4a6808acf70bb7bc991"
3520-
35213498
strip-bom@^2.0.0:
35223499
version "2.0.0"
35233500
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-2.0.0.tgz#6219a85616520491f35788bdbf1447a99c7e6b0e"
@@ -3791,10 +3768,6 @@ underscore@1.1.x:
37913768
version "1.1.7"
37923769
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.1.7.tgz#40bab84bad19d230096e8d6ef628bff055d83db0"
37933770

3794-
underscore@~1.6.0:
3795-
version "1.6.0"
3796-
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.6.0.tgz#8b38b10cacdef63337b8b24e4ff86d45aea529a8"
3797-
37983771
unicode-length@^1.0.0:
37993772
version "1.0.3"
38003773
resolved "https://registry.yarnpkg.com/unicode-length/-/unicode-length-1.0.3.tgz#5ada7a7fed51841a418a328cf149478ac8358abb"

0 commit comments

Comments
 (0)