Sfoglia il codice sorgente

add .editorconfig and auto format

pull/342/head
Guillaume Vincent 7 anni fa
parent
commit
d7567ca1c7
3 ha cambiato i file con 120 aggiunte e 103 eliminazioni
  1. +17
    -0
      .editorconfig
  2. +48
    -48
      cli.js
  3. +55
    -55
      test.js

+ 17
- 0
.editorconfig Vedi File

@@ -0,0 +1,17 @@
# editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.py]
indent_size = 4

+ 48
- 48
cli.js Vedi File

@@ -42,51 +42,51 @@ const helpMessage = `
75837019`;

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


function calcPassword(site, login, masterPassword, passwordProfile) {
LessPass.generatePassword(site, login, masterPassword, passwordProfile)
.then(function (generatedPassword) {
if (passwordProfile.clipboard) {
clipboardy.write(generatedPassword)
.then(() => {
console.log('Copied to clipboard');
process.exit();
}).catch(err => {
console.error(chalk.red('Copy failed.'));
console.error(err.message);
process.exit(1);
});
} else {
console.log(generatedPassword);
process.exit();
}
LessPass.generatePassword(site, login, masterPassword, passwordProfile)
.then(function(generatedPassword) {
if (passwordProfile.clipboard) {
clipboardy.write(generatedPassword)
.then(() => {
console.log('Copied to clipboard');
process.exit();
}).catch(err => {
console.error(chalk.red('Copy failed.'));
console.error(err.message);
process.exit(1);
});
} else {
console.log(generatedPassword);
process.exit();
}
});
}


function hasNoShortOption(options) {
let hasShortOption = false;
['l', 'u', 'd', 's'].forEach(function (shortOption) {
if (typeof options[shortOption] !== 'undefined' && options[shortOption]) {
hasShortOption = true;
}
});
return !hasShortOption;
let hasShortOption = false;
['l', 'u', 'd', 's'].forEach(function(shortOption) {
if (typeof options[shortOption] !== 'undefined' && options[shortOption]) {
hasShortOption = true;
}
});
return !hasShortOption;
}

function getOptionBoolean(options, optionString) {
let shortOption = optionString.substring(0, 1);
if (options[shortOption]) {
return true;
}
if (typeof options[optionString] === 'undefined') {
return hasNoShortOption(options);
}
return options[optionString]
let shortOption = optionString.substring(0, 1);
if (options[shortOption]) {
return true;
}
if (typeof options[optionString] === 'undefined') {
return hasNoShortOption(options);
}
return options[optionString]
}

const lowercase = getOptionBoolean(cli.flags, 'lowercase');
@@ -95,30 +95,30 @@ const symbols = getOptionBoolean(cli.flags, 'symbols');
const digits = getOptionBoolean(cli.flags, 'digits');

const passwordProfile = {
lowercase: lowercase,
uppercase: uppercase,
symbols: symbols,
numbers: digits,
clipboard: cli.flags.clipboard || false,
length: cli.flags.length || 16,
counter: cli.flags.counter || 1
lowercase: lowercase,
uppercase: uppercase,
symbols: symbols,
numbers: digits,
clipboard: cli.flags.clipboard || false,
length: cli.flags.length || 16,
counter: cli.flags.counter || 1
};

const site = cli.input[0];
const login = cli.input[1];

if (typeof site === 'undefined' && typeof login === 'undefined') {
console.log(chalk.red('site or login cannot be empty'));
console.log('type lesspass --help');
process.exit(-1);
console.log(chalk.red('site or login cannot be empty'));
console.log('type lesspass --help');
process.exit(-1);
}


if (cli.input.length === 3) {
const masterPassword = cli.input[2];
calcPassword(site, login, masterPassword, passwordProfile)
const masterPassword = cli.input[2];
calcPassword(site, login, masterPassword, passwordProfile)
} else {
read({prompt: 'master password: ', silent: true}, function (er, password) {
calcPassword(site, login, password, passwordProfile)
});
read({prompt: 'master password: ', silent: true}, function(er, password) {
calcPassword(site, login, password, passwordProfile)
});
}

+ 55
- 55
test.js Vedi File

@@ -2,136 +2,136 @@ import test from 'ava';
import execa from 'execa';

test('default options', async t => {
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password']);
t.is(stdout, '\\g-A1-.OHEwrXjT#');
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password']);
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');
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');
const {stdout} = await execa('./cli.js', ['--clipboard', 'lesspass.com', 'contact@lesspass.com', 'password']);
t.is(stdout, 'Copied to clipboard');
});

test('length', async t => {
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '--length=14']);
t.is(stdout, '=0\\A-.OHEKvwrX');
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '--length=14']);
t.is(stdout, '=0\\A-.OHEKvwrX');
});

test('length shortcut', async t => {
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '-L=14']);
t.is(stdout, '=0\\A-.OHEKvwrX');
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '-L=14']);
t.is(stdout, '=0\\A-.OHEKvwrX');
});

test('counter', async t => {
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '--counter=2']);
t.is(stdout, 'Vf:F1\'!I`8Y2`GBE');
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '--counter=2']);
t.is(stdout, 'Vf:F1\'!I`8Y2`GBE');
});

test('counter shortcut', async t => {
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '-c=2']);
t.is(stdout, 'Vf:F1\'!I`8Y2`GBE');
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '-c=2']);
t.is(stdout, 'Vf:F1\'!I`8Y2`GBE');
});

test('no lowercase', async t => {
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '--no-lowercase']);
t.is(stdout, 'JBG\\`3{+0[\"(E\\JJ');
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '--no-lowercase']);
t.is(stdout, 'JBG\\`3{+0[\"(E\\JJ');
});

test('no lowercase shortcut', async t => {
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '-uds']);
t.is(stdout, 'JBG\\`3{+0[\"(E\\JJ');
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '-uds']);
t.is(stdout, 'JBG\\`3{+0[\"(E\\JJ');
});

test('only lowercase', async t => {
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '-l']);
t.is(stdout, 'fmnujoqgcxmpffyh');
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '-l']);
t.is(stdout, 'fmnujoqgcxmpffyh');
});

test('no uppercase', async t => {
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '--no-uppercase']);
t.is(stdout, 'jbg\\`3{+0[\"(e\\jj');
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '--no-uppercase']);
t.is(stdout, 'jbg\\`3{+0[\"(e\\jj');
});

test('no uppercase shortcut', async t => {
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '-lds']);
t.is(stdout, 'jbg\\`3{+0[\"(e\\jj');
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '-lds']);
t.is(stdout, 'jbg\\`3{+0[\"(e\\jj');
});

test('only uppercase', async t => {
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '-u']);
t.is(stdout, 'FMNUJOQGCXMPFFYH');
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '-u']);
t.is(stdout, 'FMNUJOQGCXMPFFYH');
});

test('no digits', async t => {
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '--no-digits']);
t.is(stdout, ';zkB#m]mNF$;J_Ej');
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '--no-digits']);
t.is(stdout, ';zkB#m]mNF$;J_Ej');
});

test('no digits shortcut', async t => {
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '-lus']);
t.is(stdout, ';zkB#m]mNF$;J_Ej');
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '-lus']);
t.is(stdout, ';zkB#m]mNF$;J_Ej');
});

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

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

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

test('only symbols', async t => {
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '-s']);
t.is(stdout, '<"]|\'`%};\'`>-\'[,');
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'password', '-s']);
t.is(stdout, '<"]|\'`%};\'`>-\'[,');
});

test('test space in password', async t => {
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'my Master Password']);
t.is(stdout, 'D1PBB34\\#fh!LY={');
const {stdout} = await execa('./cli.js', ['lesspass.com', 'contact@lesspass.com', 'my Master Password']);
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');
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');
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');
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');
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');
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');
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');
});
const {stdout} = await execa('./cli.js', ['-d', 'lesspass.com', 'contact@lesspass.com', 'password', '-L8']);
t.is(stdout, '75837019');
});

Caricamento…
Annulla
Salva