bcup-cli 1.1.2 → 1.2.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.
Files changed (2) hide show
  1. package/package.json +3 -2
  2. package/src/cli.ts +15 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bcup-cli",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "Lightweight Buttercup password manager cli",
5
5
  "bin": {
6
6
  "bcup-cli": "bin/bcup-cli"
@@ -34,6 +34,7 @@
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"
38
39
  }
39
40
  }
package/src/cli.ts CHANGED
@@ -14,7 +14,9 @@ export function cli(args) {
14
14
  const { Vault, FileDatasource, Credentials, init, Search } = require('buttercup');
15
15
  const clipboardy = require('clipboardy');
16
16
  const chalk = require('chalk');
17
- const prompt = require('prompt-sync')();
17
+ const prompt = require('prompt-sync')({
18
+ history: require('prompt-sync-history')() //open history file
19
+ });
18
20
 
19
21
  console.log(`= ${name} v${version} (${description}) =`);
20
22
  console.log(`author: ${author}`);
@@ -34,6 +36,8 @@ export function cli(args) {
34
36
 
35
37
  let num;
36
38
  let entries;
39
+ let titleSearch;
40
+ let promptText;
37
41
  try {
38
42
  fileDatasource
39
43
  .load(credentials)
@@ -41,7 +45,9 @@ export function cli(args) {
41
45
  .then(vault => {
42
46
  do {
43
47
  console.log("\n");
44
- const titleSearch = prompt('Search text in folder or title. You can use RegExp: ')
48
+ promptText = `Search text in folder or title. You can use RegExp (${titleSearch}): `
49
+ titleSearch = prompt(promptText, titleSearch);
50
+ prompt.history.save();
45
51
  const re = new RegExp(titleSearch, 'i');
46
52
  entries = vault.findEntriesByProperty('title', re);
47
53
  const groups = vault.findGroupsByTitle(re);
@@ -61,13 +67,13 @@ export function cli(args) {
61
67
 
62
68
  console.log("\n");
63
69
  do {
64
- num = prompt('Select entry to copy or enter for search again: ')
70
+ num = prompt('Select entry to copy or press enter to search again: ')
65
71
  if (debug) console.log('num: "'+ num + '"');
66
- if (num == undefined || (num.length > 0 && (!num.match(/\d+/) || num > entries.length || num < 0))) {
72
+ if (invalidSelection(num, entries.length)) {
67
73
  console.log(`wrong selection (0-${entries.length})`)
68
74
  }
69
75
  if (num === '0') return;
70
- } while (num == undefined || num.length > 0 && (!num.match(/\d+/) || num > entries.length || num < 0))
76
+ } while (invalidSelection(num, entries.length))
71
77
  if (num === '') continue;
72
78
  const pass = entries[num - 1].getProperty('password');
73
79
  clipboardy.writeSync(pass);
@@ -79,6 +85,10 @@ export function cli(args) {
79
85
  }
80
86
  }
81
87
 
88
+ function invalidSelection(num, max) {
89
+ return num == undefined || (num.length > 0 && (!num.match(/\d+/) || num > max || num < 0))
90
+ }
91
+
82
92
  function emphSearch(string, titleSearch) {
83
93
  const chalk = require('chalk');
84
94
  const re = new RegExp(titleSearch, 'ig');