1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-06 09:20:43 +01:00

write final line with new line on non-windows

This commit is contained in:
Kyle Spearrin 2018-05-18 11:07:38 -04:00
parent f62f181136
commit 24cb2b0cdb

View File

@ -26,8 +26,12 @@ import { TemplateResponse } from './models/response/templateResponse';
const chalk = chk.default; const chalk = chk.default;
function writeLn(s: string) { function writeLn(s: string, finalLine: boolean = false) {
if (finalLine && process.platform === 'win32') {
process.stdout.write(s);
} else {
process.stdout.write(s + '\n'); process.stdout.write(s + '\n');
}
} }
export class Program { export class Program {
@ -59,7 +63,7 @@ export class Program {
program.on('command:*', () => { program.on('command:*', () => {
writeLn(chalk.redBright('Invalid command: ' + program.args.join(' '))); writeLn(chalk.redBright('Invalid command: ' + program.args.join(' ')));
process.stdout.write('See --help for a list of available commands.'); writeLn('See --help for a list of available commands.', true);
process.exit(1); process.exit(1);
}); });
@ -77,8 +81,7 @@ export class Program {
writeLn(' bw create folder eyJuYW1lIjoiTXkgRm9sZGVyIn0K'); writeLn(' bw create folder eyJuYW1lIjoiTXkgRm9sZGVyIn0K');
writeLn(' bw edit folder c7c7b60b-9c61-40f2-8ccd-36c49595ed72 eyJuYW1lIjoiTXkgRm9sZGVyMiJ9Cg=='); writeLn(' bw edit folder c7c7b60b-9c61-40f2-8ccd-36c49595ed72 eyJuYW1lIjoiTXkgRm9sZGVyMiJ9Cg==');
writeLn(' bw delete item 99ee88d2-6046-4ea7-92c2-acac464b1412'); writeLn(' bw delete item 99ee88d2-6046-4ea7-92c2-acac464b1412');
writeLn(' bw generate -lusn --length 18'); writeLn(' bw generate -lusn --length 18', true);
writeLn('');
}); });
program program
@ -97,8 +100,7 @@ export class Program {
writeLn(''); writeLn('');
writeLn(' bw login'); writeLn(' bw login');
writeLn(' bw login john@example.com myPassword321 --raw'); writeLn(' bw login john@example.com myPassword321 --raw');
writeLn(' bw login john@example.com myPassword321 --method 1 --code 249213'); writeLn(' bw login john@example.com myPassword321 --method 1 --code 249213', true);
writeLn('');
}) })
.action(async (email: string, password: string, cmd: program.Command) => { .action(async (email: string, password: string, cmd: program.Command) => {
await this.exitIfAuthed(); await this.exitIfAuthed();
@ -114,8 +116,7 @@ export class Program {
.on('--help', () => { .on('--help', () => {
writeLn('\n Examples:'); writeLn('\n Examples:');
writeLn(''); writeLn('');
writeLn(' bw logout'); writeLn(' bw logout', true);
writeLn('');
}) })
.action(async (cmd) => { .action(async (cmd) => {
await this.exitIfNotAuthed(); await this.exitIfNotAuthed();
@ -130,8 +131,7 @@ export class Program {
.on('--help', () => { .on('--help', () => {
writeLn('\n Examples:'); writeLn('\n Examples:');
writeLn(''); writeLn('');
writeLn(' bw lock'); writeLn(' bw lock', true);
writeLn('');
}) })
.action(async (cmd) => { .action(async (cmd) => {
await this.exitIfNotAuthed(); await this.exitIfNotAuthed();
@ -154,8 +154,7 @@ export class Program {
writeLn(''); writeLn('');
writeLn(' bw unlock'); writeLn(' bw unlock');
writeLn(' bw unlock myPassword321'); writeLn(' bw unlock myPassword321');
writeLn(' bw unlock myPassword321 --raw'); writeLn(' bw unlock myPassword321 --raw', true);
writeLn('');
}) })
.action(async (password, cmd) => { .action(async (password, cmd) => {
await this.exitIfNotAuthed(); await this.exitIfNotAuthed();
@ -175,8 +174,7 @@ export class Program {
writeLn(''); writeLn('');
writeLn(' bw sync'); writeLn(' bw sync');
writeLn(' bw sync -f'); writeLn(' bw sync -f');
writeLn(' bw sync --last'); writeLn(' bw sync --last', true);
writeLn('');
}) })
.action(async (cmd) => { .action(async (cmd) => {
await this.exitIfLocked(); await this.exitIfLocked();
@ -211,8 +209,7 @@ export class Program {
writeLn(' bw list items --folderid null'); writeLn(' bw list items --folderid null');
writeLn(' bw list items --organizationid !null'); writeLn(' bw list items --organizationid !null');
writeLn(' bw list items --folderid 60556c31-e649-4b5d-8daf-fc1c391a1bf2 --organizationid !null'); writeLn(' bw list items --folderid 60556c31-e649-4b5d-8daf-fc1c391a1bf2 --organizationid !null');
writeLn(' bw list folders --search email'); writeLn(' bw list folders --search email', true);
writeLn('');
}) })
.action(async (object, cmd) => { .action(async (object, cmd) => {
await this.exitIfLocked(); await this.exitIfLocked();
@ -255,8 +252,7 @@ export class Program {
'--output ./photo.jpg'); '--output ./photo.jpg');
writeLn(' bw get attachment photo.jpg --itemid 99ee88d2-6046-4ea7-92c2-acac464b1412 --raw'); writeLn(' bw get attachment photo.jpg --itemid 99ee88d2-6046-4ea7-92c2-acac464b1412 --raw');
writeLn(' bw get folder email'); writeLn(' bw get folder email');
writeLn(' bw get template folder'); writeLn(' bw get template folder', true);
writeLn('');
}) })
.action(async (object, id, cmd) => { .action(async (object, id, cmd) => {
await this.exitIfLocked(); await this.exitIfLocked();
@ -287,8 +283,8 @@ export class Program {
writeLn(''); writeLn('');
writeLn(' bw create folder eyJuYW1lIjoiTXkgRm9sZGVyIn0K'); writeLn(' bw create folder eyJuYW1lIjoiTXkgRm9sZGVyIn0K');
writeLn(' echo \'eyJuYW1lIjoiTXkgRm9sZGVyIn0K\' | bw create folder'); writeLn(' echo \'eyJuYW1lIjoiTXkgRm9sZGVyIn0K\' | bw create folder');
writeLn(' bw create attachment --file ./myfile.csv --itemid 16b15b89-65b3-4639-ad2a-95052a6d8f66'); writeLn(' bw create attachment --file ./myfile.csv ' +
writeLn(''); '--itemid 16b15b89-65b3-4639-ad2a-95052a6d8f66', true);
}) })
.action(async (object, encodedJson, cmd) => { .action(async (object, encodedJson, cmd) => {
await this.exitIfLocked(); await this.exitIfLocked();
@ -319,8 +315,7 @@ export class Program {
writeLn(''); writeLn('');
writeLn(' bw edit folder 5cdfbd80-d99f-409b-915b-f4c5d0241b02 eyJuYW1lIjoiTXkgRm9sZGVyMiJ9Cg=='); writeLn(' bw edit folder 5cdfbd80-d99f-409b-915b-f4c5d0241b02 eyJuYW1lIjoiTXkgRm9sZGVyMiJ9Cg==');
writeLn(' echo \'eyJuYW1lIjoiTXkgRm9sZGVyMiJ9Cg==\' | ' + writeLn(' echo \'eyJuYW1lIjoiTXkgRm9sZGVyMiJ9Cg==\' | ' +
'bw edit folder 5cdfbd80-d99f-409b-915b-f4c5d0241b02'); 'bw edit folder 5cdfbd80-d99f-409b-915b-f4c5d0241b02', true);
writeLn('');
}) })
.action(async (object, id, encodedJson, cmd) => { .action(async (object, id, encodedJson, cmd) => {
await this.exitIfLocked(); await this.exitIfLocked();
@ -348,8 +343,7 @@ export class Program {
writeLn(''); writeLn('');
writeLn(' bw delete item 7063feab-4b10-472e-b64c-785e2b870b92'); writeLn(' bw delete item 7063feab-4b10-472e-b64c-785e2b870b92');
writeLn(' bw delete folder 5cdfbd80-d99f-409b-915b-f4c5d0241b02'); writeLn(' bw delete folder 5cdfbd80-d99f-409b-915b-f4c5d0241b02');
writeLn(' bw delete attachment b857igwl1dzrs2 --itemid 310d5ffd-e9a2-4451-af87-ea054dce0f78'); writeLn(' bw delete attachment b857igwl1dzrs2 --itemid 310d5ffd-e9a2-4451-af87-ea054dce0f78', true);
writeLn('');
}) })
.action(async (object, id, cmd) => { .action(async (object, id, cmd) => {
await this.exitIfLocked(); await this.exitIfLocked();
@ -369,8 +363,7 @@ export class Program {
writeLn(' bw export'); writeLn(' bw export');
writeLn(' bw export myPassword321'); writeLn(' bw export myPassword321');
writeLn(' bw export --output ./exp/bw.csv'); writeLn(' bw export --output ./exp/bw.csv');
writeLn(' bw export myPassword321 --output bw.csv'); writeLn(' bw export myPassword321 --output bw.csv', true);
writeLn('');
}) })
.action(async (password, cmd) => { .action(async (password, cmd) => {
await this.exitIfLocked(); await this.exitIfLocked();
@ -400,8 +393,7 @@ export class Program {
writeLn(' bw generate'); writeLn(' bw generate');
writeLn(' bw generate -u -l --length 18'); writeLn(' bw generate -u -l --length 18');
writeLn(' bw generate -ulns --length 25'); writeLn(' bw generate -ulns --length 25');
writeLn(' bw generate -ul'); writeLn(' bw generate -ul', true);
writeLn('');
}) })
.action(async (cmd) => { .action(async (cmd) => {
const command = new GenerateCommand(this.main.passwordGenerationService); const command = new GenerateCommand(this.main.passwordGenerationService);
@ -419,8 +411,7 @@ export class Program {
writeLn(''); writeLn('');
writeLn(' Examples:'); writeLn(' Examples:');
writeLn(''); writeLn('');
writeLn(' echo \'{"name":"My Folder"}\' | bw encode'); writeLn(' echo \'{"name":"My Folder"}\' | bw encode', true);
writeLn('');
}) })
.action(async (object, id, cmd) => { .action(async (object, id, cmd) => {
const command = new EncodeCommand(); const command = new EncodeCommand();
@ -439,8 +430,7 @@ export class Program {
writeLn(' Examples:'); writeLn(' Examples:');
writeLn(''); writeLn('');
writeLn(' bw config server https://bw.company.com'); writeLn(' bw config server https://bw.company.com');
writeLn(' bw config server bitwarden.com'); writeLn(' bw config server bitwarden.com', true);
writeLn('');
}) })
.action(async (setting, value, cmd) => { .action(async (setting, value, cmd) => {
const command = new ConfigCommand(this.main.environmentService); const command = new ConfigCommand(this.main.environmentService);
@ -458,8 +448,7 @@ export class Program {
writeLn(''); writeLn('');
writeLn(' Examples:'); writeLn(' Examples:');
writeLn(''); writeLn('');
writeLn(' bw update'); writeLn(' bw update', true);
writeLn('');
}) })
.action(async (object, id, cmd) => { .action(async (object, id, cmd) => {
// TODO // TODO
@ -476,7 +465,7 @@ export class Program {
private processResponse(response: Response) { private processResponse(response: Response) {
if (!response.success) { if (!response.success) {
if (process.env.BW_QUIET !== 'true') { if (process.env.BW_QUIET !== 'true') {
process.stdout.write(chalk.redBright(response.message)); writeLn(chalk.redBright(response.message), true);
} }
process.exit(1); process.exit(1);
return; return;
@ -500,7 +489,7 @@ export class Program {
} }
if (out != null && process.env.BW_QUIET !== 'true') { if (out != null && process.env.BW_QUIET !== 'true') {
process.stdout.write(out); writeLn(out, true);
} }
} }
process.exit(); process.exit();
@ -537,7 +526,7 @@ export class Program {
await this.exitIfNotAuthed(); await this.exitIfNotAuthed();
const key = await this.main.cryptoService.getKey(); const key = await this.main.cryptoService.getKey();
if (key == null) { if (key == null) {
process.stdout.write(chalk.redBright('Vault is locked.')); writeLn(chalk.redBright('Vault is locked.'), true);
process.exit(1); process.exit(1);
} }
} }
@ -546,7 +535,7 @@ export class Program {
const authed = await this.main.userService.isAuthenticated(); const authed = await this.main.userService.isAuthenticated();
if (authed) { if (authed) {
const email = await this.main.userService.getEmail(); const email = await this.main.userService.getEmail();
process.stdout.write(chalk.redBright('You are already logged in as ' + email + '.')); writeLn(chalk.redBright('You are already logged in as ' + email + '.'), true);
process.exit(1); process.exit(1);
} }
} }
@ -554,7 +543,7 @@ export class Program {
private async exitIfNotAuthed() { private async exitIfNotAuthed() {
const authed = await this.main.userService.isAuthenticated(); const authed = await this.main.userService.isAuthenticated();
if (!authed) { if (!authed) {
process.stdout.write(chalk.redBright('You are not logged in.')); writeLn(chalk.redBright('You are not logged in.'), true);
process.exit(1); process.exit(1);
} }
} }