Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aggregated-cli-reporter

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aggregated-cli-reporter

A way of reporting results of multiple processes without overflowing the terminal

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

aggregated-cli-reporter

A way of reporting results of multiple processes without overflowing the terminal.

It will rewrite the previous lines, so there never are more visible than the latest message.

Note: If something else is writing to stdout, it will interfere with this module, since this module can only delete the x last lines, which no longer matches the actual lines written to stdout.

Usage

The interface:

class AggregatedCLIReporter {
	constructor({ showTime = true, showName = false })
	set(name, messages, { showTime = true, showName = false })
}

Creating a new reporter

import AggregatedCLIReporter from 'aggregated-cli-reporter'
// Or
const AggregatedCLIReporter = require('aggregated-cli-reporter')

const reporter = new AggregatedCLIReporter()

The constructor can take some configuration options:

  • showTime: Shows a timestamp that the message was received. Defaults to true.
  • showName: Shows the name passed to #set(). Defaults to false.
const reporter = new AggregatedCLIReporter({
	showTime: false,
	showName: true,
})

Writing logs

The reporter.set() method sets the latest output for a specific name.

reporter.set('tool1', 'Some message')

/* output:
12:45:12: Some message
*/

There can only ever be one message per name, but there is no limit to the number of names.

reporter.set('tool2', 'Some other message')

/* output:
12:45:12: Some message
12:47:22: Some other message
*/

// skip 12 seconds

reporter.set('tool2', 'Something new happened')

/* output:
12:45:12: Some message
12:47:34: Something new happened
*/

The names are printed in the order that they were last modified, so the latest message is always in the bottom.

reporter.set('tool1', 'Something happened to the first tool')

/* output:
12:47:34: Something new happened
12:49:01: Something happened to the first tool
*/

Any characters can be added, including colors and newlines.

reporter.set('tool1', 'Tool 1 is split\non lines')
/* output:
12:47:34: Something new happened
13:01:43: Tool 1 is split
on lines
*/

The message can also be an array, in which case the tool will print each value on a separate line, all prefixed.

reporter.set('tool1', [ 'Something happened', 'that should', 'be split\non lines' ])

/* output:
12:47:34: Something new happened
13:02:23: Something happened
13:02:23: that should
13:02:23: be split
on lines
*/

Overriding options per message

The #set() call takes the same arguments as the constructor. The options will override the default for that specific message only.

const reporter = new AggregatedCLIReporter({ showTime: true, showName: true })

reporter.set('tool1', 'abc')
/* output:
12:34:56: tool1: abc
*/

reporter.set('tool1', 'abc', { showName: false })
/* output:
12:34:56: abc
*/

reporter.set('tool2', 'def', { showTime: false })
/* output:
12:34:56: abc
tool2: def
*/

reporter.set('tool3', [ 'ghi', 'jkl' ])
/* output:
12:34:56: abc
tool2: def
12:34:56: tool3: ghi
12:34:56: tool3: jkl
*/

Keywords

FAQs

Package last updated on 11 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc