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
1 changed files with 29 additions and 40 deletions

View File

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