bcup-cli 1.1.2 → 1.3.0
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 +2 -4
- package/package.json +9 -5
- package/src/cli.ts +26 -12
package/bin/bcup-cli
CHANGED
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bcup-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Lightweight Buttercup password manager cli",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"bin": {
|
|
6
|
-
"bcup-cli": "bin/
|
|
7
|
+
"bcup-cli": "bin/cli.mjs"
|
|
7
8
|
},
|
|
8
9
|
"main": "index.js",
|
|
9
10
|
"scripts": {
|
|
@@ -25,15 +26,18 @@
|
|
|
25
26
|
"dependencies": {
|
|
26
27
|
"@types/node": "^13.9.2",
|
|
27
28
|
"arg": "^4.1.3",
|
|
28
|
-
"buttercup": "^
|
|
29
|
+
"buttercup": "^7.7.1",
|
|
29
30
|
"chalk": "^4.1.0",
|
|
30
31
|
"clipboardy": "^2.3.0",
|
|
31
32
|
"config": "^3.3.0",
|
|
32
33
|
"crypto-random-string": "^3.3.0",
|
|
33
|
-
"esm": "^3.2.25",
|
|
34
34
|
"global": "^4.4.0",
|
|
35
35
|
"js-yaml": "^3.13.1",
|
|
36
36
|
"lodash": "^4.17.15",
|
|
37
|
-
"prompt-sync": "^4.2.0"
|
|
37
|
+
"prompt-sync": "^4.2.0",
|
|
38
|
+
"prompt-sync-history": "^1.0.1"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"tsx": "^4.21.0"
|
|
38
42
|
}
|
|
39
43
|
}
|
package/src/cli.ts
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import arg from 'arg';
|
|
4
|
-
import
|
|
4
|
+
import flatten from 'lodash/flatten';
|
|
5
|
+
import uniqBy from 'lodash/uniqBy';
|
|
5
6
|
import { name, version, description, author, license, repository } from '../package.json';
|
|
7
|
+
import { Vault, FileDatasource, Credentials, init } 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';
|
|
6
13
|
|
|
7
14
|
export function cli(args) {
|
|
8
15
|
const options = parseArgumentsIntoOptions(args);
|
|
9
16
|
const debug = options.debug || false;
|
|
10
17
|
if (debug) console.log(args);
|
|
11
|
-
const
|
|
12
|
-
const bcupFile = options.bcupPath || `${homedir}/.bcup-cli/vault.bcup`;
|
|
18
|
+
const bcupFile = options.bcupPath || `${homedir()}/.bcup-cli/vault.bcup`;
|
|
13
19
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const prompt = require('prompt-sync')();
|
|
20
|
+
const prompt = promptSync({
|
|
21
|
+
history: history() //open history file
|
|
22
|
+
});
|
|
18
23
|
|
|
19
24
|
console.log(`= ${name} v${version} (${description}) =`);
|
|
20
25
|
console.log(`author: ${author}`);
|
|
@@ -34,6 +39,8 @@ export function cli(args) {
|
|
|
34
39
|
|
|
35
40
|
let num;
|
|
36
41
|
let entries;
|
|
42
|
+
let titleSearch;
|
|
43
|
+
let promptText;
|
|
37
44
|
try {
|
|
38
45
|
fileDatasource
|
|
39
46
|
.load(credentials)
|
|
@@ -41,7 +48,9 @@ export function cli(args) {
|
|
|
41
48
|
.then(vault => {
|
|
42
49
|
do {
|
|
43
50
|
console.log("\n");
|
|
44
|
-
|
|
51
|
+
promptText = `Search text in folder or title. You can use RegExp (${titleSearch}): `
|
|
52
|
+
titleSearch = prompt(promptText, titleSearch);
|
|
53
|
+
prompt.history.save();
|
|
45
54
|
const re = new RegExp(titleSearch, 'i');
|
|
46
55
|
entries = vault.findEntriesByProperty('title', re);
|
|
47
56
|
const groups = vault.findGroupsByTitle(re);
|
|
@@ -61,13 +70,13 @@ export function cli(args) {
|
|
|
61
70
|
|
|
62
71
|
console.log("\n");
|
|
63
72
|
do {
|
|
64
|
-
num = prompt('Select entry to copy or enter
|
|
73
|
+
num = prompt('Select entry to copy or press enter to search again: ')
|
|
65
74
|
if (debug) console.log('num: "'+ num + '"');
|
|
66
|
-
if (
|
|
75
|
+
if (invalidSelection(num, entries.length)) {
|
|
67
76
|
console.log(`wrong selection (0-${entries.length})`)
|
|
68
77
|
}
|
|
69
78
|
if (num === '0') return;
|
|
70
|
-
} while (
|
|
79
|
+
} while (invalidSelection(num, entries.length))
|
|
71
80
|
if (num === '') continue;
|
|
72
81
|
const pass = entries[num - 1].getProperty('password');
|
|
73
82
|
clipboardy.writeSync(pass);
|
|
@@ -79,8 +88,11 @@ export function cli(args) {
|
|
|
79
88
|
}
|
|
80
89
|
}
|
|
81
90
|
|
|
91
|
+
function invalidSelection(num, max) {
|
|
92
|
+
return num == undefined || (num.length > 0 && (!num.match(/\d+/) || num > max || num < 0))
|
|
93
|
+
}
|
|
94
|
+
|
|
82
95
|
function emphSearch(string, titleSearch) {
|
|
83
|
-
const chalk = require('chalk');
|
|
84
96
|
const re = new RegExp(titleSearch, 'ig');
|
|
85
97
|
|
|
86
98
|
let res;
|
|
@@ -108,3 +120,5 @@ function parseArgumentsIntoOptions(rawArgs) {
|
|
|
108
120
|
bcupPath: args['--bcup-path'],
|
|
109
121
|
};
|
|
110
122
|
}
|
|
123
|
+
|
|
124
|
+
cli(process.argv);
|