haskell-te: d85092103b4df90f4e8d8f7b7641ccc9b2b9df99

     1: { bash, jq, mkBin, utillinux }:
     2: 
     3: mkBin {
     4:   name   = "hsNameVersion";
     5:   paths  = [ bash jq utillinux ];
     6:   script = ''
     7:     #!${bash}/bin/bash
     8: 
     9:     # Takes a string containing a Haskell package name, returns JSON with
    10:     # the version (if found) and the package name (with version stripped, if
    11:     # given)
    12: 
    13:     if echo "$1" | grep -- "-[0-9][0-9.]*$" > /dev/null
    14:     then
    15:       # We have a version number in our package field; split it up
    16:          NAME=$(echo "$1" | rev | cut -d '-' -f 2- | rev)
    17:       VERSION=$(echo "$1" | rev | cut -d '-' -f 1  | rev)
    18: 
    19:       jq -n --arg name "$NAME"       \
    20:             --arg version "$VERSION" \
    21:             '{"package":$name,"version":$version}'
    22:     else
    23:       # We don't have a version number in our package field; leave as-is
    24:       jq -n --arg name "$1" '{"package":$name}'
    25:     fi
    26:   '';
    27: }

Generated by git2html.