Browse Source

options order should not matter

fix https://github.com/lesspass/lesspass/issues/146
pull/342/head
Guillaume Vincent 7 years ago
parent
commit
4a36e64bcd
2 changed files with 52 additions and 2 deletions
  1. +7
    -2
      cli.js
  2. +45
    -0
      test.js

+ 7
- 2
cli.js View File

@@ -6,7 +6,7 @@ const LessPass = require('lesspass');
const read = require('read'); const read = require('read');
const chalk = require('chalk'); const chalk = require('chalk');


const cli = meow(`
const helpMessage = `
Usage Usage
$ lesspass <site> <login> [masterPassword] [options] $ lesspass <site> <login> [masterPassword] [options]


@@ -39,7 +39,12 @@ const cli = meow(`
# only digits and length of 8 # only digits and length of 8
$ lesspass lesspass.com contact@lesspass.com -d -L8 $ lesspass lesspass.com contact@lesspass.com -d -L8
master password: master password:
75837019`, {alias: {L: 'length', c: 'counter', C: 'clipboard'}});
75837019`;

const cli = meow(helpMessage, {
alias: {L: 'length', c: 'counter', C: 'clipboard'},
boolean: ['l', 'u', 'd', 's', 'C', 'clipboard']
});




function calcPassword(site, login, masterPassword, passwordProfile) { function calcPassword(site, login, masterPassword, passwordProfile) {


+ 45
- 0
test.js View File

@@ -6,6 +6,16 @@ test('default options', async t => {
t.is(stdout, '\\g-A1-.OHEwrXjT#'); t.is(stdout, '\\g-A1-.OHEwrXjT#');
}); });


test('options can be before parameters', async t => {
const {stdout} = await execa('./cli.js', ['-C', 'lesspass.com', 'contact@lesspass.com', 'password']);
t.is(stdout, 'Copied to clipboard');
});

test('long options can be before parameters', async t => {
const {stdout} = await execa('./cli.js', ['--clipboard', 'lesspass.com', 'contact@lesspass.com', 'password']);
t.is(stdout, 'Copied to clipboard');
});

test('length', async t => { test('length', async t => {
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '--length=14']); const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '--length=14']);
t.is(stdout, '=0\\A-.OHEKvwrX'); t.is(stdout, '=0\\A-.OHEKvwrX');
@@ -89,4 +99,39 @@ test('only symbols', async t => {
test('test space in password', async t => { test('test space in password', async t => {
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'my Master Password']); const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'my Master Password']);
t.is(stdout, 'D1PBB34\\#fh!LY={'); t.is(stdout, 'D1PBB34\\#fh!LY={');
});

test('doc 1', async t => {
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '--no-symbols']);
t.is(stdout, 'OlfK63bmUhqrGODR');
});

test('doc 1 options before', async t => {
const {stdout} = await execa('./cli.js', ['--no-symbols', 'lesspass.com', 'contact@lesspass.com', 'password']);
t.is(stdout, 'OlfK63bmUhqrGODR');
});

test('doc 2', async t => {
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '-lud']);
t.is(stdout, 'OlfK63bmUhqrGODR');
});

test('doc 2 options before', async t => {
const {stdout} = await execa('./cli.js', ['-lud', 'lesspass.com', 'contact@lesspass.com', 'password']);
t.is(stdout, 'OlfK63bmUhqrGODR');
});

test('doc 3', async t => {
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '-d', '-L8']);
t.is(stdout, '75837019');
});

test('doc 3 options before', async t => {
const {stdout} = await execa('./cli.js', ['-d', '-L8', 'lesspass.com', 'contact@lesspass.com', 'password']);
t.is(stdout, '75837019');
});

test('doc 3 options before and after', async t => {
const {stdout} = await execa('./cli.js', ['-d', 'lesspass.com', 'contact@lesspass.com', 'password', '-L8']);
t.is(stdout, '75837019');
}); });

Loading…
Cancel
Save