Skip to content

Commit

Permalink
Basic cli script setup see #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Filippo Conti committed Apr 30, 2018
1 parent edbd1cf commit 8169855
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 12 deletions.
95 changes: 95 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env node

const { version } = require('../package.json');
const program = require('commander');
const pwner = new (require('../dist/pwned.node'))();

const printErr = err => {
console.log('An error occurred', err);
};

const printRes = res => {
if (Object.keys(res).length === 0) {
console.log('No results found.');
return;
}
console.log(JSON.stringify(res, null, 2));
};

program.name('pwned').version(version);

// List all the available breaches
program
.command('breaches')
.option(
'-d, --domain <domain>',
'Filters the result set to only breaches against the domain specified'
)
.action(options => {
pwner
.breaches({
domain: options.domain
})
.then(printRes)
.catch(printErr);
});

// Return a list of all breaches a particular account has been involved in
program
.command('breached <account>')
.option('-t, --truncate', 'Returns only the name of the breach')
.option('-u, --unverified', 'Returns breaches that have been flagged as unverified')
.option(
'-d, --domain <domain>',
'Filters the result set to only breaches against the domain specified'
)
.action((account, options) => {
pwner
.breachedAccount(account, {
domain: options.domain,
truncateResponse: options.truncate,
includeUnverified: options.unverified
})
.then(printRes)
.catch(printErr);
});

// Return single breach details by name
program.command('breach <name>').action(name => {
pwner
.breach(name)
.then(printRes)
.catch(printErr);
});

// Return all the data classes in the systems
program.command('dataclasses').action(() => {
pwner
.dataClasses()
.then(printRes)
.catch(printErr);
});

// Return all pastes for an account
program.command('pasteaccount <account>').action(account => {
pwner
.pasteAccount(account)
.then(printRes)
.catch(printErr);
});

// // TODO: Handle the 404 cases and investigates on missing count on response
// // Check if a password been exposed in data breaches and exists on HIBP database
// program
// .command('password <password>')
// .option('-o, --original-hash')
// .action((password, options) => {
// pwner
// .pwnedPassword(password, {
// originalPasswordIsAHash: options.originalHash
// })
// .then(() => printRes({ found: true }))
// .catch(printErr);
// });

program.parse(process.argv);
28 changes: 16 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,28 @@
},
"files": ["lib"],
"main": "dist/pwned.node.js",
"bin": {
"pwned": "./lib/cli.js"
},
"keywords": ["haveibeenpwned", "javascript-client"],
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-preset-es2015": "^6.24.1",
"coveralls": "^3.0.0",
"eslint": "^4.17.0",
"eslint": "^4.19.1",
"eslint-config-prettier": "^2.9.0",
"eslint-config-xo": "^0.19.0",
"eslint-config-xo": "^0.22.0",
"eslint-plugin-prettier": "^2.6.0",
"husky": "^0.14.3",
"jest": "^22.2.2",
"jest-cli": "^22.2.2",
"lint-staged": "^6.1.0",
"nock": "^9.1.6",
"nsp": "^3.1.0",
"prettier": "^1.10.2",
"webpack": "^3.11.0"
"jest": "^22.4.3",
"jest-cli": "^22.4.3",
"lint-staged": "^7.0.5",
"nock": "^9.2.5",
"nsp": "^3.2.1",
"prettier": "^1.12.1",
"webpack-cli": "^2.1.2"
},
"scripts": {
"prepublish": "nsp check",
Expand Down Expand Up @@ -64,6 +67,7 @@
},
"license": "MIT",
"dependencies": {
"node-fetch": "^2.0.0"
"commander": "^2.15.1",
"node-fetch": "^2.1.2"
}
}

0 comments on commit 8169855

Please sign in to comment.