2018-05-14 23:13:57 +02:00
|
|
|
import * as program from 'commander';
|
|
|
|
|
|
|
|
import { Response } from '../models/response';
|
|
|
|
import { StringResponse } from '../models/response/stringResponse';
|
|
|
|
|
2018-05-17 04:40:48 +02:00
|
|
|
import { CliUtils } from '../utils';
|
|
|
|
|
2018-05-14 23:13:57 +02:00
|
|
|
export class EncodeCommand {
|
2018-05-17 04:40:48 +02:00
|
|
|
async run(cmd: program.Command): Promise<Response> {
|
|
|
|
if (process.stdin.isTTY) {
|
|
|
|
return Response.badRequest('No stdin was piped in.');
|
2018-05-14 23:13:57 +02:00
|
|
|
}
|
2018-05-17 04:40:48 +02:00
|
|
|
const input = await CliUtils.readStdin();
|
|
|
|
const b64 = new Buffer(input, 'utf8').toString('base64');
|
|
|
|
const res = new StringResponse(b64);
|
|
|
|
return Response.success(res);
|
2018-05-14 23:13:57 +02:00
|
|
|
}
|
|
|
|
}
|