import { Response , ResponseStream } from "@scramjet/api-client" ; import { Command } from "commander" ; import { Writable } from "stream" ; /**
 * Command from commander contains obj with whole params, that user provides to the console.
 */ param { "json" | "pretty" } type param { any } object function display ( type = "pretty" , object ) { if ( type === "json" ) { console . log ( JSON . stringify ( object ) ) ; } else { console . dir ( object ) ; } } param _program param object export async function displayObject ( _program , object ) { display ( _program . opts ( ) . format , object ) ; } param { Command } _program param { Promise < ResponseStream > } response param { Writable } output returns { Promise } export async function displayStream ( _program , response , output = process . stdout ) { try { const resp = await response ; resp . data ?. pipe ( output ) ; return new Promise ( ( res , rej ) => resp . data ?. on ( "finish" , res ) . on ( "error" , rej ) ) ; } catch ( e ) { console . error ( e && e . stack || e ) ; process . exitCode = e . exitCode || 1 ; return Promise . reject ( ) ; } } param _program { _program } param { Promise < Response | void > } response export async function displayEntity ( _program , response ) { const res = await response ; if ( ! res ) { return ; } display ( _program . opts ( ) . format , res . data ) ; }