1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-30 08:10:34 +01:00

encode command

This commit is contained in:
Kyle Spearrin 2018-05-14 17:13:57 -04:00
parent 85770b7cbb
commit 9b99c299e4
3 changed files with 45 additions and 1 deletions

View File

@ -0,0 +1,34 @@
import * as program from 'commander';
import { CipherService } from 'jslib/abstractions/cipher.service';
import { FolderService } from 'jslib/abstractions/folder.service';
import { Response } from '../models/response';
import { StringResponse } from '../models/response/stringResponse';
export class EncodeCommand {
run(cmd: program.Command): Promise<Response> {
if (process.stdin == null || process.stdin.isTTY) {
return Promise.resolve(Response.badRequest('No stdin was piped in.'));
}
return new Promise((resolve, reject) => {
let input: string = '';
process.stdin.setEncoding('utf8');
process.stdin.on('readable', () => {
while (true) {
const chunk = process.stdin.read();
if (chunk == null) {
break;
}
input += chunk;
}
});
process.stdin.on('end', () => {
const b64 = new Buffer(input, 'utf8').toString('base64');
var res = new StringResponse(b64);
resolve(Response.success(res));
});
});
}
}

View File

@ -125,7 +125,7 @@ export class GetCommand {
template = SecureNoteRequest.template(); template = SecureNoteRequest.template();
break; break;
default: default:
return Response.badRequest('Unknown object.'); return Response.badRequest('Unknown template object.');
} }
const res = new TemplateResponse(template); const res = new TemplateResponse(template);

View File

@ -12,6 +12,7 @@ import { Response } from './models/response';
import { ListResponse } from './models/response/listResponse'; import { ListResponse } from './models/response/listResponse';
import { StringResponse } from './models/response/stringResponse'; import { StringResponse } from './models/response/stringResponse';
import { TemplateResponse } from './models/response/templateResponse'; import { TemplateResponse } from './models/response/templateResponse';
import { EncodeCommand } from './commands/encode.command';
export class Program { export class Program {
constructor(private main: Main) { } constructor(private main: Main) { }
@ -87,6 +88,15 @@ export class Program {
this.processResponse(response); this.processResponse(response);
}); });
program
.command('encode')
.description('Base64 encode stdin.')
.action(async (object, id, cmd) => {
const command = new EncodeCommand();
const response = await command.run(cmd);
this.processResponse(response);
});
program program
.parse(process.argv); .parse(process.argv);
} }