#!/bin/bash
#
# Purpose:  List or display COBOL copylib files from /usr/local/share/gnucobol/copy
# Location: /usr/local/sbin
# Author:   Jay Moseley
# Date:     Sat September 20, 2019
#

# no argument or single argument='--help' := show help and exit
if  [ $# -eq 0 ] || [ "$1" == "--help" ]; then
    echo "copybook requires 1 or 2 argument:"
    echo "         --help to show this message"
    echo "  <or>   --list to show all copybooks in directory"
    echo "  <or>   --show {copybook name}"
    exit
fi

# single argument="--list" := list contents of copybook directory
if [ $# -eq 1 ] && [ "$1" == "--list" ]; then
   echo "Contents of /usr/local/share/gnucobol/copy"
   ls -1 /usr/local/share/gnucobol/copy/
   exit
fi

# first argument="--show" := show contents of second argument
if [ $# -eq 2 ] && [ "$1" == "--show" ]; then
   if [ -e /usr/local/share/gnucobol/copy/$2 ]; then
      echo "Contents of /usr/local/share/gnucobol/copy/$2"
      cat /usr/local/share/gnucobol/copy/$2
   else
      echo "File $2 not found"
   fi
  exit
fi