feat(xo-cli): support @=- to output to stdout

This commit is contained in:
Julien Fontanet
2020-06-05 13:49:08 +02:00
parent 9f0b22d3e9
commit 2f9cbec07e

View File

@@ -27,6 +27,7 @@ const prettyMs = require('pretty-ms')
const progressStream = require('progress-stream')
const pw = require('pw')
const Xo = require('xo-lib').default
const { PassThrough } = require('stream')
// -------------------------------------------------------------------
@@ -50,6 +51,17 @@ async function connect() {
return xo
}
function createOutputStream(path) {
if (path !== undefined && path !== '-') {
return createWriteStream(path)
}
// introduce a through stream because stdout is not a normal stream!
const stream = new PassThrough()
stream.pipe(process.stdout)
return stream
}
const FLAG_RE = /^--([^=]+)(?:=([^]*))?$/
function extractFlags(args) {
const flags = {}
@@ -375,7 +387,7 @@ async function call(args) {
if (key === '$getFrom') {
ensurePathParam(method, file)
url = resolveUrl(baseUrl, result[key])
const output = createWriteStream(file)
const output = createOutputStream(file)
const response = await hrp(url)
const progress = progressStream(