bcup-cli 1.1.0 → 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 +4 -3
  2. package/src/cli.ts +22 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bcup-cli",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Lightweight Buttercup password manager cli",
5
5
  "bin": {
6
6
  "bcup-cli": "bin/bcup-cli"
@@ -19,7 +19,7 @@
19
19
  "cli",
20
20
  "bcup-cli"
21
21
  ],
22
- "author": "Ignacio Aliende García",
22
+ "author": "Ignacio Aliende García <ialiendeg@gmail.com>",
23
23
  "license": "MIT",
24
24
  "repository": "https://github.com/Usabi/bcup-cli",
25
25
  "dependencies": {
@@ -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
@@ -2,6 +2,7 @@
2
2
 
3
3
  import arg from 'arg';
4
4
  import { flatten, uniqBy } from 'lodash';
5
+ import { name, version, description, author, license, repository } from '../package.json';
5
6
 
6
7
  export function cli(args) {
7
8
  const options = parseArgumentsIntoOptions(args);
@@ -13,7 +14,15 @@ export function cli(args) {
13
14
  const { Vault, FileDatasource, Credentials, init, Search } = require('buttercup');
14
15
  const clipboardy = require('clipboardy');
15
16
  const chalk = require('chalk');
16
- const prompt = require('prompt-sync')();
17
+ const prompt = require('prompt-sync')({
18
+ history: require('prompt-sync-history')() //open history file
19
+ });
20
+
21
+ console.log(`= ${name} v${version} (${description}) =`);
22
+ console.log(`author: ${author}`);
23
+ console.log(`license: ${license}`);
24
+ console.log(`repository: ${repository}\n`);
25
+
17
26
  const password = prompt('Vault password: ', { echo: '*' })
18
27
  if (password == undefined || password.length == 0) return
19
28
 
@@ -27,6 +36,8 @@ export function cli(args) {
27
36
 
28
37
  let num;
29
38
  let entries;
39
+ let titleSearch;
40
+ let promptText;
30
41
  try {
31
42
  fileDatasource
32
43
  .load(credentials)
@@ -34,7 +45,9 @@ export function cli(args) {
34
45
  .then(vault => {
35
46
  do {
36
47
  console.log("\n");
37
- 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();
38
51
  const re = new RegExp(titleSearch, 'i');
39
52
  entries = vault.findEntriesByProperty('title', re);
40
53
  const groups = vault.findGroupsByTitle(re);
@@ -54,13 +67,13 @@ export function cli(args) {
54
67
 
55
68
  console.log("\n");
56
69
  do {
57
- num = prompt('Select entry to copy or enter for search again: ')
70
+ num = prompt('Select entry to copy or press enter to search again: ')
58
71
  if (debug) console.log('num: "'+ num + '"');
59
- if (num == undefined || (num.length > 0 && (!num.match(/\d+/) || num > entries.length || num < 0))) {
72
+ if (invalidSelection(num, entries.length)) {
60
73
  console.log(`wrong selection (0-${entries.length})`)
61
74
  }
62
75
  if (num === '0') return;
63
- } while (num == undefined || num.length > 0 && (!num.match(/\d+/) || num > entries.length || num < 0))
76
+ } while (invalidSelection(num, entries.length))
64
77
  if (num === '') continue;
65
78
  const pass = entries[num - 1].getProperty('password');
66
79
  clipboardy.writeSync(pass);
@@ -72,6 +85,10 @@ export function cli(args) {
72
85
  }
73
86
  }
74
87
 
88
+ function invalidSelection(num, max) {
89
+ return num == undefined || (num.length > 0 && (!num.match(/\d+/) || num > max || num < 0))
90
+ }
91
+
75
92
  function emphSearch(string, titleSearch) {
76
93
  const chalk = require('chalk');
77
94
  const re = new RegExp(titleSearch, 'ig');