[lastbash-cvs] lastbash lastbash,1.88,1.89
Status: Beta
Brought to you by:
cstroie
|
From: Costin S. <cs...@us...> - 2006-12-07 22:41:15
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27300 Modified Files: lastbash Log Message: Use getopts and show a better help. Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.88 retrieving revision 1.89 diff -u -d -r1.88 -r1.89 --- lastbash 7 Dec 2006 22:08:23 -0000 1.88 +++ lastbash 7 Dec 2006 22:41:11 -0000 1.89 @@ -107,13 +107,6 @@ # Function: Print usage summary {{{1 #----------------------------------------------------------------------------- -function usage() -{ - echo "Usage: ${0##*/} [-aAdvh] [-p player] [-r refresh] [-u username] [-c command] [station]" -} - -# Function: Print usage summary {{{1 -#----------------------------------------------------------------------------- function url_encode() { # $1 - string to encode @@ -131,6 +124,12 @@ read -n 1 -s -t "$1" SLEEP_KEY } +# Function: Print program name and version {{{1 +#----------------------------------------------------------------------------- +function prog_ver() +{ + echo "${PROG_NAME} v${PROG_VER}" +} # Function: Initialization {{{1 #----------------------------------------------------------------------------- @@ -1855,26 +1854,56 @@ unset KEY done } + +# Function: Print usage summary {{{1 +#----------------------------------------------------------------------------- +function usage() +{ + prog_ver + echo + echo "Usage: ${0##*/} [options] [station]" + echo + echo "Options:" + echo " -a,-A Enable/Disable the autoplay feature" + echo " -d Enable the debug mode" + echo " -g HTTP_client Set the HTTP client to use for the webservice" + echo " -p player Set the backend player" + echo " -r refresh Set the metadata refresh interval" + echo " -u username Set new username to login with and clear the password" + echo " -c command Set the command to send to the running instance" + echo " -v Show program name and version" + echo " -h Show this quick help" + echo + echo "HTTP clients: ${HTTP_CLIENTS} builtin auto" + echo "Players: ${PLAYERS} auto" + echo + echo "Station: any valid Last.fm station, such as the following:" + echo " lastfm://globaltags/rock" + echo " lastfm://user/cstroie/neighbours" + echo " lastfm://group/LastBASH" +} # }}}1 # The main part #----------------------------------------------------------------------------- # Check commandline options -while [ "${1:0:1}" = "-" ] +while getopts ":c:g:p:r:u:aAdvh" OPTION do - case "$1" in - "-a") AUTO_PLAY="y" ;; - "-A") AUTO_PLAY="n" ;; - "-c") LASTFM_COMMAND="$2"; shift 1 ;; - "-d") DEBUG="y" ;; - "-p") PLAYER="$2"; shift 1 ;; - "-r") REFRESH_INTERVAL="$2"; shift 1 ;; - "-u") LASTFM_USER="$2"; LASTFM_PASS=""; shift 1 ;; - "-v") echo "${PROG_NAME} v${PROG_VER}" && exit 0 ;; - "-h") usage && exit 0 ;; + case "${OPTION}" in + "a") AUTO_PLAY="y" ;; + "A") AUTO_PLAY="n" ;; + "c") LASTFM_COMMAND="${OPTARG}" ;; + "d") DEBUG="y" ;; + "g") HTTP_CLIENT="${OPTARG}" ;; + "p") PLAYER="${OPTARG}" ;; + "r") REFRESH_INTERVAL="${OPTARG}" ;; + "u") LASTFM_USER="${OPTARG}"; LASTFM_PASS="" ;; + "v") prog_ver && exit 0 ;; + "h") usage && exit 0 ;; + "?") echo "Unexpected argument: \"${OPTARG}\""; exit 1 ;; + ":") echo "Required argument not found for \"${OPTARG}\""; exit 1 ;; esac - shift 1 done # Write the debug header @@ -1886,19 +1915,19 @@ first_instance && FIRST_INSTANCE="y" # This should be the Last.fm station -if [[ "$1" =~ "^lastfm://" ]] +if [[ "${!OPTIND}" =~ "^lastfm://" ]] then # This is the new station to tune into if [ "${FIRST_INSTANCE}" ] then # Store the station to load after the init - LASTFM_STATION="$1" + LASTFM_STATION="${!OPTIND}" else # Another instance is already running - remote_call "STATION $1" + remote_call "STATION ${!OPTIND}" exit 0 fi -elif [ "$1" ] +elif [ "${!OPTIND}" ] then # The string is unexpected usage |