-
Notifications
You must be signed in to change notification settings - Fork 6
/
bl-profile-query.js
executable file
·41 lines (36 loc) · 1.33 KB
/
bl-profile-query.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env node
const config = require('./config');
const commander = require('commander');
const util = require('./util');
commander
.option('-i, --id <id>', 'filter profiles by id')
.option('-q, --query <query>', 'filter profiles by username, full name, or email address')
.option('-j, --json', 'output data in json format')
.parse(process.argv);
util.loadJwt().then(jwt => {
let headers = { "Authorization": "Bearer " + jwt };
let datatypeTable = {};
util.queryProfiles(headers, {
id: commander.id,
search: commander.query
}).then(profiles=>{
if (commander.json) console.log(JSON.stringify(profiles));
else console.log(formatProfiles(headers, profiles));
}).catch(err=>{
console.error(err);
});
});
function formatProfiles(headers, data) {
data = data.sort((a, b) => a.id > b.id);
let resultArray = data.map(profile => {
let info = [];
info.push("sub: " + profile.sub);
info.push("Username: " + profile.username);
info.push("Full Name: " + profile.fullname);
info.push("Email: " + profile.email);
info.push("Active: " + profile.active);
return info.join('\n');
});
resultArray.push("(Returned " + data.length + " " + util.pluralize("result", data) + ")");
return resultArray.join('\n\n');
}