Command line argument parsing set up. Help system added. Place holder for post_music function.
This commit is contained in:
parent
5cea37fe56
commit
5a4abe1643
48
ratatoskr.sh
48
ratatoskr.sh
@ -3,6 +3,22 @@
|
|||||||
# Hopefully one day this will be a full featured Pleroma client.
|
# Hopefully one day this will be a full featured Pleroma client.
|
||||||
# Let's see how far we can get. :)
|
# Let's see how far we can get. :)
|
||||||
|
|
||||||
|
# Display usage information.
|
||||||
|
help() {
|
||||||
|
echo "${0##*/}"
|
||||||
|
echo "Released under the terms of the WTFPL License"
|
||||||
|
echo -e "Usage:\n"
|
||||||
|
echo "With no arguments, open the interactive client."
|
||||||
|
for i in "${!command[@]}" ; do
|
||||||
|
echo "-${i/:/ <parameter>}: ${command[${i}]}"
|
||||||
|
done | sort
|
||||||
|
echo
|
||||||
|
echo "Configuration files can be found in ${configPath}"
|
||||||
|
echo
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Get an oauth token
|
# Get an oauth token
|
||||||
get_oauth_token() {
|
get_oauth_token() {
|
||||||
echo "Welcome to ${softwareName}!"
|
echo "Welcome to ${softwareName}!"
|
||||||
@ -22,7 +38,7 @@ get_oauth_token() {
|
|||||||
# Load the new variables from the configuration file
|
# Load the new variables from the configuration file
|
||||||
source "${configPath}/${configFile}"
|
source "${configPath}/${configFile}"
|
||||||
# Create the url to get the oauth token
|
# Create the url to get the oauth token
|
||||||
local url="${instanceURL}/oauth/authorize?client_id=${client_id}&redirect_uri=https://billy.wolfe.casa/ratatoskr-success.html&response_type=code&scope=read%20write%20follow%20push"
|
local url="${instanceURL}/oauth/authorize?client_id=${client_id}&redirect_uri=${redirectURI}&response_type=code&scope=read%20write%20follow%20push"
|
||||||
echo "Please open the following url in your browser."
|
echo "Please open the following url in your browser."
|
||||||
echo "Copy the generated token, and paste it here, then press enter to continue."
|
echo "Copy the generated token, and paste it here, then press enter to continue."
|
||||||
echo
|
echo
|
||||||
@ -37,6 +53,15 @@ get_oauth_token() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Functions that deal with posting.
|
||||||
|
|
||||||
|
# Post music with -M flag
|
||||||
|
post_music() {
|
||||||
|
echo "Work in progress..."
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Variable initialization
|
# Variable initialization
|
||||||
configPath="${XDG_CONFIG_HOME:-$HOME/.config}/ratatoskr" # Path for settings, usually ~/.config/ratatoskr
|
configPath="${XDG_CONFIG_HOME:-$HOME/.config}/ratatoskr" # Path for settings, usually ~/.config/ratatoskr
|
||||||
configFile="default.conf" # The default config file, eventually will support multiple accounts.
|
configFile="default.conf" # The default config file, eventually will support multiple accounts.
|
||||||
@ -48,9 +73,30 @@ softwareName="Ratatoskr" # The name of the client.
|
|||||||
# make sure the configuration path exists:
|
# make sure the configuration path exists:
|
||||||
mkdir -p "${configPath}"
|
mkdir -p "${configPath}"
|
||||||
|
|
||||||
|
# Associative array of command line parameters and short description of what they do.
|
||||||
|
declare -A command=(
|
||||||
|
[h]="Help, show usage information for ${0##*/}."
|
||||||
|
[M]="Post the currently playing music track, requires playerctl."
|
||||||
|
)
|
||||||
|
|
||||||
# if the default file doesn't exist, create it
|
# if the default file doesn't exist, create it
|
||||||
if [[ ! -e "${configPath}/${configFile}" ]]; then
|
if [[ ! -e "${configPath}/${configFile}" ]]; then
|
||||||
get_oauth_token
|
get_oauth_token
|
||||||
|
else
|
||||||
|
# Read configuration file
|
||||||
|
source "${configPath}/${configFile}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Handle command line parameters
|
||||||
|
# Convert the keys of the associative array to a format usable by getopts
|
||||||
|
args="${!command[*]}"
|
||||||
|
args="${args//[[:space:]]/}"
|
||||||
|
while getopts "${args}" i ; do
|
||||||
|
case "$i" in
|
||||||
|
h) help;;
|
||||||
|
M) post_music;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
Loading…
Reference in New Issue
Block a user