bcup-cli 1.3.4 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/bcup-cli +1 -1
- package/dist/cli.d.ts +2 -0
- package/{src → dist}/cli.js +35 -40
- package/dist/cli.js.map +1 -0
- package/package.json +3 -3
- package/src/cli.ts +0 -124
- package/src/cli.ts.with_search +0 -87
package/bin/bcup-cli
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
|
-
exec
|
|
2
|
+
exec node "$(dirname "$0")/../dist/cli.js" "$@"
|
package/dist/cli.d.ts
ADDED
package/{src → dist}/cli.js
RENAMED
|
@@ -1,42 +1,37 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const os_1 = require("os");
|
|
14
|
-
const clipboardy_1 = __importDefault(require("clipboardy"));
|
|
15
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
16
|
-
const prompt_sync_1 = __importDefault(require("prompt-sync"));
|
|
17
|
-
const prompt_sync_history_1 = __importDefault(require("prompt-sync-history"));
|
|
18
|
-
function cli(args) {
|
|
2
|
+
import arg from 'arg';
|
|
3
|
+
import flatten from 'lodash/flatten';
|
|
4
|
+
import uniqBy from 'lodash/uniqBy';
|
|
5
|
+
import { name, version, description, author, license, repository } from '../package.json';
|
|
6
|
+
import { Vault, FileDatasource, Credentials, init } from 'buttercup';
|
|
7
|
+
import { homedir } from 'os';
|
|
8
|
+
import clipboardy from 'clipboardy';
|
|
9
|
+
import chalk from 'chalk';
|
|
10
|
+
import promptSync from 'prompt-sync';
|
|
11
|
+
import history from 'prompt-sync-history';
|
|
12
|
+
export function cli(args) {
|
|
19
13
|
const options = parseArgumentsIntoOptions(args);
|
|
20
14
|
const debug = options.debug || false;
|
|
21
15
|
if (debug)
|
|
22
16
|
console.log(args);
|
|
23
|
-
const bcupFile = options.bcupPath || `${
|
|
24
|
-
const prompt = (
|
|
25
|
-
history: (
|
|
17
|
+
const bcupFile = options.bcupPath || `${homedir()}/.bcup-cli/vault.bcup`;
|
|
18
|
+
const prompt = promptSync({
|
|
19
|
+
history: history() //open history file
|
|
26
20
|
});
|
|
27
|
-
console.log(`= ${
|
|
28
|
-
console.log(`author: ${
|
|
29
|
-
console.log(`license: ${
|
|
30
|
-
console.log(`repository: ${
|
|
21
|
+
console.log(`= ${name} v${version} (${description}) =`);
|
|
22
|
+
console.log(`author: ${author}`);
|
|
23
|
+
console.log(`license: ${license}`);
|
|
24
|
+
console.log(`repository: ${repository}\n`);
|
|
31
25
|
const password = prompt('Vault password: ', { echo: '*' });
|
|
32
26
|
if (password == undefined || password.length == 0)
|
|
33
27
|
return;
|
|
34
|
-
|
|
35
|
-
const datasourceCredentials =
|
|
28
|
+
init();
|
|
29
|
+
const datasourceCredentials = Credentials.fromDatasource({
|
|
30
|
+
type: 'file',
|
|
36
31
|
path: bcupFile
|
|
37
32
|
}, password);
|
|
38
|
-
const fileDatasource = new
|
|
39
|
-
const credentials =
|
|
33
|
+
const fileDatasource = new FileDatasource(datasourceCredentials);
|
|
34
|
+
const credentials = Credentials.fromPassword(password);
|
|
40
35
|
let num;
|
|
41
36
|
let entries;
|
|
42
37
|
let titleSearch;
|
|
@@ -44,29 +39,28 @@ function cli(args) {
|
|
|
44
39
|
try {
|
|
45
40
|
fileDatasource
|
|
46
41
|
.load(credentials)
|
|
47
|
-
.then(({
|
|
42
|
+
.then(({ history }) => Vault.createFromHistory(history))
|
|
48
43
|
.then(vault => {
|
|
49
44
|
do {
|
|
50
45
|
console.log("\n");
|
|
51
46
|
promptText = `Search text in folder or title. You can use RegExp (${titleSearch}): `;
|
|
52
47
|
titleSearch = prompt(promptText, titleSearch);
|
|
53
|
-
prompt.history.save();
|
|
54
48
|
const re = new RegExp(titleSearch, 'i');
|
|
55
49
|
entries = vault.findEntriesByProperty('title', re);
|
|
56
50
|
const groups = vault.findGroupsByTitle(re);
|
|
57
51
|
const groupEntries = groups.map(group => group.getEntries());
|
|
58
|
-
entries = (
|
|
52
|
+
entries = flatten(groupEntries).concat(entries);
|
|
59
53
|
if (debug)
|
|
60
54
|
console.log(entries);
|
|
61
|
-
entries = (
|
|
55
|
+
entries = uniqBy(entries, entry => entry.id);
|
|
62
56
|
console.log('0 exit');
|
|
63
57
|
entries.forEach((entry, idx) => {
|
|
64
|
-
const title = emphSearch(entry.getProperty('title'), titleSearch);
|
|
58
|
+
const title = emphSearch(String(entry.getProperty('title')), titleSearch);
|
|
65
59
|
const username = entry.getProperty('username');
|
|
66
60
|
const url = entry.getProperty('URL');
|
|
67
61
|
const group = emphSearch(entry.getGroup().getTitle(), titleSearch);
|
|
68
|
-
const sep = ` ${
|
|
69
|
-
console.log(`${idx + 1} ${group}${
|
|
62
|
+
const sep = ` ${chalk.bold('|')} `;
|
|
63
|
+
console.log(`${idx + 1} ${group}${chalk.bold('->')}${title}${sep}url: ${url}${sep}username: ${username}`);
|
|
70
64
|
});
|
|
71
65
|
console.log("\n");
|
|
72
66
|
do {
|
|
@@ -81,8 +75,8 @@ function cli(args) {
|
|
|
81
75
|
} while (invalidSelection(num, entries.length));
|
|
82
76
|
if (num === '')
|
|
83
77
|
continue;
|
|
84
|
-
const pass = entries[num - 1].getProperty('password');
|
|
85
|
-
|
|
78
|
+
const pass = entries[Number(num) - 1].getProperty('password');
|
|
79
|
+
clipboardy.writeSync(String(pass));
|
|
86
80
|
} while (true);
|
|
87
81
|
});
|
|
88
82
|
}
|
|
@@ -91,19 +85,19 @@ function cli(args) {
|
|
|
91
85
|
}
|
|
92
86
|
}
|
|
93
87
|
function invalidSelection(num, max) {
|
|
94
|
-
return num == undefined || (num.length > 0 && (!num.match(/\d+/) || num > max || num < 0));
|
|
88
|
+
return num == undefined || (num.length > 0 && (!num.match(/\d+/) || Number(num) > max || Number(num) < 0));
|
|
95
89
|
}
|
|
96
90
|
function emphSearch(string, titleSearch) {
|
|
97
91
|
const re = new RegExp(titleSearch, 'ig');
|
|
98
92
|
let res;
|
|
99
93
|
let newString = string;
|
|
100
94
|
while ((res = re.exec(string)) !== null) {
|
|
101
|
-
newString = newString.slice(0, res.index) +
|
|
95
|
+
newString = newString.slice(0, res.index) + chalk.red(res[0]) + newString.slice(res.index + res[0].length);
|
|
102
96
|
}
|
|
103
97
|
return newString;
|
|
104
98
|
}
|
|
105
99
|
function parseArgumentsIntoOptions(rawArgs) {
|
|
106
|
-
const args = (
|
|
100
|
+
const args = arg({
|
|
107
101
|
'--debug': Boolean,
|
|
108
102
|
'--bcup-path': String,
|
|
109
103
|
'-d': '--debug',
|
|
@@ -117,3 +111,4 @@ function parseArgumentsIntoOptions(rawArgs) {
|
|
|
117
111
|
};
|
|
118
112
|
}
|
|
119
113
|
cli(process.argv);
|
|
114
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,MAAM,MAAM,eAAe,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC1F,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,IAAI,EAAwB,MAAM,WAAW,CAAC;AAC3F,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,UAAU,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,OAAO,MAAM,q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,CAAC;KACvB,CACF,CAAC;IACF,OAAO;QACL,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,KAAK;QAC/B,QAAQ,EAAE,IAAI,CAAC,aAAa,CAAC;KAC9B,CAAC;AACH,CAAC;AAED,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bcup-cli",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.5",
|
|
4
4
|
"description": "Lightweight Buttercup password manager cli",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"bcup-cli": "bin/bcup-cli"
|
|
8
8
|
},
|
|
9
|
-
"main": "
|
|
9
|
+
"main": "dist/cli.js",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "tsc",
|
|
12
12
|
"prepare": "npm run build",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
16
|
"bin/",
|
|
17
|
-
"
|
|
17
|
+
"dist"
|
|
18
18
|
],
|
|
19
19
|
"keywords": [
|
|
20
20
|
"buttercup",
|
package/src/cli.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import arg from 'arg';
|
|
4
|
-
import flatten from 'lodash/flatten';
|
|
5
|
-
import uniqBy from 'lodash/uniqBy';
|
|
6
|
-
import { name, version, description, author, license, repository } from '../package.json';
|
|
7
|
-
import { Vault, FileDatasource, Credentials, init, DatasourceLoadedData } from 'buttercup';
|
|
8
|
-
import { homedir } from 'os';
|
|
9
|
-
import clipboardy from 'clipboardy'
|
|
10
|
-
import chalk from 'chalk'
|
|
11
|
-
import promptSync from 'prompt-sync';
|
|
12
|
-
import history from 'prompt-sync-history';
|
|
13
|
-
|
|
14
|
-
export function cli(args: string[]): void {
|
|
15
|
-
const options = parseArgumentsIntoOptions(args);
|
|
16
|
-
const debug = options.debug || false;
|
|
17
|
-
if (debug) console.log(args);
|
|
18
|
-
const bcupFile = options.bcupPath || `${homedir()}/.bcup-cli/vault.bcup`;
|
|
19
|
-
|
|
20
|
-
const prompt = promptSync({
|
|
21
|
-
history: history() //open history file
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
console.log(`= ${name} v${version} (${description}) =`);
|
|
25
|
-
console.log(`author: ${author}`);
|
|
26
|
-
console.log(`license: ${license}`);
|
|
27
|
-
console.log(`repository: ${repository}\n`);
|
|
28
|
-
|
|
29
|
-
const password = prompt('Vault password: ', { echo: '*' })
|
|
30
|
-
if (password == undefined || password.length == 0) return
|
|
31
|
-
|
|
32
|
-
init();
|
|
33
|
-
const datasourceCredentials = Credentials.fromDatasource({
|
|
34
|
-
type: 'file',
|
|
35
|
-
path: bcupFile
|
|
36
|
-
}, password)
|
|
37
|
-
const fileDatasource = new FileDatasource(datasourceCredentials);
|
|
38
|
-
|
|
39
|
-
const credentials = Credentials.fromPassword(password);
|
|
40
|
-
|
|
41
|
-
let num;
|
|
42
|
-
let entries;
|
|
43
|
-
let titleSearch: string;
|
|
44
|
-
let promptText;
|
|
45
|
-
try {
|
|
46
|
-
fileDatasource
|
|
47
|
-
.load(credentials)
|
|
48
|
-
.then(({ history }: DatasourceLoadedData) => Vault.createFromHistory(history))
|
|
49
|
-
.then(vault => {
|
|
50
|
-
do {
|
|
51
|
-
console.log("\n");
|
|
52
|
-
promptText = `Search text in folder or title. You can use RegExp (${titleSearch}): `
|
|
53
|
-
titleSearch = prompt(promptText, titleSearch);
|
|
54
|
-
const re = new RegExp(titleSearch, 'i');
|
|
55
|
-
entries = vault.findEntriesByProperty('title', re);
|
|
56
|
-
const groups = vault.findGroupsByTitle(re);
|
|
57
|
-
const groupEntries = groups.map(group => group.getEntries());
|
|
58
|
-
entries = flatten(groupEntries).concat(entries);
|
|
59
|
-
if (debug) console.log(entries);
|
|
60
|
-
entries = uniqBy(entries, entry => entry.id);
|
|
61
|
-
console.log('0 exit');
|
|
62
|
-
entries.forEach((entry, idx) => {
|
|
63
|
-
const title = emphSearch(String(entry.getProperty('title')), titleSearch);
|
|
64
|
-
const username = entry.getProperty('username');
|
|
65
|
-
const url = entry.getProperty('URL');
|
|
66
|
-
const group = emphSearch(entry.getGroup().getTitle(), titleSearch);
|
|
67
|
-
const sep = ` ${chalk.bold('|')} `
|
|
68
|
-
console.log(`${idx + 1} ${group}${chalk.bold('->')}${title}${sep}url: ${url}${sep}username: ${username}`);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
console.log("\n");
|
|
72
|
-
do {
|
|
73
|
-
num = prompt('Select entry to copy or press enter to search again: ')
|
|
74
|
-
if (debug) console.log('num: "'+ num + '"');
|
|
75
|
-
if (invalidSelection(num, entries.length)) {
|
|
76
|
-
console.log(`wrong selection (0-${entries.length})`)
|
|
77
|
-
}
|
|
78
|
-
if (num === '0') return;
|
|
79
|
-
} while (invalidSelection(num, entries.length))
|
|
80
|
-
if (num === '') continue;
|
|
81
|
-
const pass = entries[Number(num) - 1].getProperty('password');
|
|
82
|
-
clipboardy.writeSync(String(pass));
|
|
83
|
-
} while (true)
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
catch(error) {
|
|
87
|
-
console.error(error);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function invalidSelection(num: string, max: number) {
|
|
92
|
-
return num == undefined || (num.length > 0 && (!num.match(/\d+/) || Number(num) > max || Number(num) < 0))
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function emphSearch(string: string, titleSearch: string) {
|
|
96
|
-
const re = new RegExp(titleSearch, 'ig');
|
|
97
|
-
|
|
98
|
-
let res;
|
|
99
|
-
let newString = string;
|
|
100
|
-
while ((res = re.exec(string)) !== null) {
|
|
101
|
-
newString = newString.slice(0, res.index) + chalk.red(res[0]) + newString.slice(res.index + res[0].length)
|
|
102
|
-
}
|
|
103
|
-
return newString;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function parseArgumentsIntoOptions(rawArgs: any) {
|
|
107
|
-
const args = arg(
|
|
108
|
-
{
|
|
109
|
-
'--debug': Boolean,
|
|
110
|
-
'--bcup-path': String,
|
|
111
|
-
'-d': '--debug',
|
|
112
|
-
'-b': '--bcup-path',
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
argv: rawArgs.slice(2),
|
|
116
|
-
}
|
|
117
|
-
);
|
|
118
|
-
return {
|
|
119
|
-
debug: args['--debug'] || false,
|
|
120
|
-
bcupPath: args['--bcup-path'],
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
cli(process.argv);
|
package/src/cli.ts.with_search
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import arg from 'arg';
|
|
4
|
-
import { flatten, uniqBy } from 'lodash';
|
|
5
|
-
|
|
6
|
-
export function cli(args) {
|
|
7
|
-
const options = parseArgumentsIntoOptions(args);
|
|
8
|
-
const debug = options.debug || false;
|
|
9
|
-
if (debug) console.log(args);
|
|
10
|
-
const homedir = require('os').homedir();
|
|
11
|
-
const bcupFile = options.bcupPath || `${homedir}/.bcup-cli/vault.bcup`;
|
|
12
|
-
|
|
13
|
-
const { Vault, FileDatasource, Credentials, init, Search } = require('buttercup');
|
|
14
|
-
const clipboardy = require('clipboardy');
|
|
15
|
-
const prompt = require('prompt-sync')();
|
|
16
|
-
const password = prompt('Vault password: ', { echo: '*' })
|
|
17
|
-
|
|
18
|
-
init();
|
|
19
|
-
const datasourceCredentials = Credentials.fromDatasource({
|
|
20
|
-
path: bcupFile
|
|
21
|
-
}, password)
|
|
22
|
-
const fileDatasource = new FileDatasource(datasourceCredentials);
|
|
23
|
-
|
|
24
|
-
const credentials = Credentials.fromPassword(password);
|
|
25
|
-
|
|
26
|
-
let num;
|
|
27
|
-
let entries;
|
|
28
|
-
try {
|
|
29
|
-
fileDatasource
|
|
30
|
-
.load(credentials)
|
|
31
|
-
.then(({ format, history }) => Vault.createFromHistory(history, format))
|
|
32
|
-
.then(async vault => {
|
|
33
|
-
do {
|
|
34
|
-
const search = new Search([vault]);
|
|
35
|
-
const titleSearch = prompt('Search text (in folder or title): ')
|
|
36
|
-
entries = await search.prepare().then(
|
|
37
|
-
() => {
|
|
38
|
-
console.log("\n");
|
|
39
|
-
return search.searchByTerm(titleSearch);
|
|
40
|
-
}
|
|
41
|
-
);
|
|
42
|
-
const re = new RegExp(titleSearch, 'i');
|
|
43
|
-
const groups = vault.findGroupsByTitle(re);
|
|
44
|
-
const groupEntries = groups.map(group => group.getEntries());
|
|
45
|
-
entries = flatten(groupEntries).concat(entries);
|
|
46
|
-
if (debug) console.log(entries);
|
|
47
|
-
entries = uniqBy(entries, entry => entry.id);
|
|
48
|
-
console.log('0 exit');
|
|
49
|
-
entries.forEach((entry, idx) => {
|
|
50
|
-
const title = entry.getProperty('title');
|
|
51
|
-
const username = entry.getProperty('username');
|
|
52
|
-
const url = entry.getProperty('URL');
|
|
53
|
-
const group = entry.getGroup().getTitle();
|
|
54
|
-
console.log(`${idx + 1} ${group} / ${title} | url: ${url} | username: ${username}`);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
console.log("\n");
|
|
58
|
-
num = prompt('Select entry to copy or enter for search again: ')
|
|
59
|
-
if (debug) console.log(num);
|
|
60
|
-
} while (!num.length)
|
|
61
|
-
if (num == 0) return;
|
|
62
|
-
const pass = entries[num - 1].getProperty('password');
|
|
63
|
-
clipboardy.writeSync(pass);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
catch(error) {
|
|
67
|
-
console.error(error);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function parseArgumentsIntoOptions(rawArgs) {
|
|
72
|
-
const args = arg(
|
|
73
|
-
{
|
|
74
|
-
'--debug': Boolean,
|
|
75
|
-
'--bcup-path': String,
|
|
76
|
-
'-d': '--debug',
|
|
77
|
-
'-b': '--bcup-path',
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
argv: rawArgs.slice(2),
|
|
81
|
-
}
|
|
82
|
-
);
|
|
83
|
-
return {
|
|
84
|
-
debug: args['--debug'] || false,
|
|
85
|
-
bcupPath: args['--bcup-path'],
|
|
86
|
-
};
|
|
87
|
-
}
|