#!/bin/sh -e

usage() {
    printf %s "\
$(basename "$0")
  for easy viewing of csv files with column and less

commands:
  [-h]elp       - Display this message.

arguments:
  [file.csv]
"
  exit 0
}

log() {
  printf '%s\n' "$*"
}
err() {
  printf '%s\n' "Error: $*" >&2
}
fatal() {
  err "$@"
  exit 1
}

# get the options
# shellcheck disable=SC2249
while getopts ':h' option; do
  case ${option} in
    h) usage ;;
    \?) fatal "Invalid option" ;;
  esac
done

# check and see if path is valid
if ! [ -f "$1" ]; then
  echo "File path is incorrect, or does not exist."
  exit 1
fi

# will view the .csv file supplied with less if no other
# command like options are given.
column -s, -t < "$1" | less -#2 -N -S
