gratis – Parsing library (or tool) for command line output of common tools


I am trying to call a couple of common software tools from PowerShell scripts within Azure DevOps pipelines – for example:

  • npm
  • tsc
  • dotnet
  • GraphViz
  • pdflatex

Each of these will happily write status messages to stdout and/or stderr.

To make sense of these (and, in particular, to decide which ones are so relevant that DevOps should be notified about them), I need to parse this stdout/stderr output. Unfortunately (albeit understandably), each of those tools picks its own way to format its output1.

Rather than figure out the relevant RegEx patterns for each of the tools myself, is there a free-to-use (preferrably open source) library or tool

  • that takes the stdout and stderr output of another tool as its input (e.g. as an array of strings, or as an array of strings marked as originating from stdout/stderr)
  • comes with a host of modules equipped to recognize the output of many common tools like the ones I listed above
    • (it is fully expected I have to explicitly name which tool the output I am providing originates from)
  • recognizes which consecutive lines go together, forming one logical message
  • and maybe parses enough to determine some basic distinction of the message type, e.g. error vs. warning vs. info
  • in order to finally return a list of these messages using the same data structure or syntax regardless of the input tool

?


Example:

Assume I compile some TypeScript and tsc prints the following lines to stderr:

my-class.ts(14,6): error TS1005: '=>' expected.

14 func = x x + 2;
        ~~

my-class.ts(20,9): error TS1002: Unterminated string literal.

20 b = 'abc;
           ~

From this, I’d expect the following output – here printed as JSON, depending on how the library works, it could also be some data structure in the respective language/environment:

[{
  "type": "error",
  "message": "my-class.ts(14,6): error TS1005: '=>' expected.\n\n14 func = x x + 2;\n        ~~"
}, {
  "type": "error",
  "message": "my-class.ts(20,9): error TS1002: Unterminated string literal.\n\n20 b = 'abc;\n           ~"
}]

1: And I don’t think they generally offer a CLI switch to write a more standardized/parseable format – a feature that I know mainly from unit testing tools.



Source link

Related Posts

About The Author

Add Comment