Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

cli.table throws when output is piped to head #149

Open
dotnetCarpenter opened this issue Apr 15, 2020 · 1 comment
Open

cli.table throws when output is piped to head #149

dotnetCarpenter opened this issue Apr 15, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@dotnetCarpenter
Copy link

OS: Linux
cli-ux: 5.4.5
node: v12.16.1
head: head (GNU coreutils) 8.28

When piping the output of cli.table() to head I get Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed.

Error:

Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
    at Object.Table.options.printLine (~/oclif_bugs/head/node_modules/cli-ux/lib/styled/table.js:39:60)
    at ~/oclif_bugs/head/node_modules/cli-ux/lib/styled/table.js:257:25
    at Array.forEach (<anonymous>)
    at Table.outputTable (~/oclif_bugs/head/node_modules/cli-ux/lib/styled/table.js:243:27)
    at Table.display (~/oclif_bugs/head/node_modules/cli-ux/lib/styled/table.js:103:22)
    at Object.table (~/oclif_bugs/head/node_modules/cli-ux/lib/styled/table.js:263:39)
    at HeadCommand.run (~/oclif_bugs/head/src/index.js:19:9)

Steps To Reproduce

Create a single oclif app.
Copy / Paste the script below as a command:

const {Command, flags} = require('@oclif/command')
const fs = require('fs').promises
const path = require('path')
const lockfile = require('@yarnpkg/lockfile')
const { cli } = require('cli-ux')
const R = require('ramda')

class HeadCommand extends Command {
  async run() {
    const {flags} = this.parse(HeadCommand)

    const yarnLock = new URL(`file://${path.resolve(__dirname, '..')}/yarn.lock`)
    const lotOfText = await fs.readFile(yarnLock)
    const data = lockfile.parse(lotOfText.toString()).object
    const dataList = []

    R.forEachObjIndexed((value) => { dataList.push(R.pick(['version'], value))}, data)

    cli.table(dataList, {version:{}}, flags)
  }
}

HeadCommand.description = `Describe the command here
...
Extra documentation goes here
`

HeadCommand.flags = {
  // add flags from cli.table
  ...cli.table.flags(),
  // add --version flag to show CLI version
  version: flags.version({char: 'v'}),
  // add --help flag to show CLI version
  help: flags.help({char: 'h'}),
}

module.exports = HeadCommand

Install: yarn add cli-ux @yarnpkg/lockfile ramda

Run: ./bin/run | head

If you have created a "multi" app, then the path to yarn.lock need to be changed.

@RasPhilCo
Copy link
Contributor

Confirmed. Will take a look.

@RasPhilCo RasPhilCo added the bug Something isn't working label Jul 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants