Monday, March 18, 2019

A bunch of CLASPs

CLASP - Command-Line Argument Sorting and Parsing - is a suite of libraries for sophisticated parsing of command-line arguments and presenting the parsed elements - flags, options, values - in a usable form. The original C/C++ library was released in 2011; variants for other languages have been released from time to time since.

Of necessity (but also enjoying it), currently I'm building systems in a bunch of different technologies, including GoJavascript (NodeB), Python, and Ruby. As such, I have new/updated versions of the CLASP variants for these languages:


Each of the newly-released projects - Go, js, Python - contains  (on GitHub) an EXAMPLES.md file, with links to examples. CLASP.Ruby will provide examples in a forthcoming release.

Friday, February 15, 2019

Simple cat in CoffeeScript

Further to the post "Simple cat in Node", here's a version in CoffeeScript.

#! /usr/bin/env coffee

fs = require('fs')
readline = require('readline')
paths = process.argv.slice(2)

cat = (path) ->

stm = if path then fs.createReadStream(path) else process.stdin

readline.createInterface(
input: stm
).on 'line', (line) ->

process.stdout.write line + '\n'

return

  return

if 0 == paths.length

cat null

return
else

  // process each one at a time
paths.forEach (path) ->

cat path

return


As you can see, it's very simple in structure to the JavaScript version; just simpler and with fewer parentheses. It can be further simplified by removing all the return statements, as every one is redundant in this case:

#! /usr/bin/env coffee

fs = require('fs')
readline = require('readline')
paths = process.argv.slice(2)

cat = (path) ->

stm = if path then fs.createReadStream(path) else process.stdin

readline.createInterface(
input: stm
).on 'line', (line) ->

process.stdout.write line + '\n'

if 0 == paths.length

cat null
else

  // process each one at a time
paths.forEach (path) ->

cat path