Rails rake task invoked with parameters by bash script
namespace :data do
desc 'Data loader'
task :load, [:data_file] do |t, args|
puts "in rake task"
p args
end
end
#! /usr/bin/env bash
set -o nounset
set -o errexit
if ( ! getopts ":c:" opt); then
rake data:load
else
while getopts ":c:" opt; do
case $opt in
c)
if [[ -f $OPTARG ]] && [[ -r $OPTARG ]]; then
rake "data:load[${OPTARG}]"
else
echo "${OPTARG} is not a readable file"
exit 1
fi
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
fi