diff --git a/bambu.sh b/bambu.sh index 08faff8..0e63e36 100755 --- a/bambu.sh +++ b/bambu.sh @@ -86,9 +86,51 @@ function bambu_status() { mqtt_command '{"pushing": { "sequence_id": 1, "command": "pushall"}, "user_id":"1234567890"}' } -function bambu_lsdir() { - local directory="$(preprocess_directory_path "$1")" - curl_ftps_command "$directory" +function bambu_file() { + local subcommand="$1" + shift + + case "$subcommand" in + ls) + bambu_ls "$@" + ;; + upload) + bambu_upload "$@" + ;; + rm) + bambu_rm "$@" + ;; + *) + die "Unknown subcommand $subcommand" + ;; + esac +} + +function bambu_ls() { + local is_file="false" + local path="" + + while [ ! -z "$1" ]; do + case "$1" in + -f|--file) + is_file="true" + shift + ;; + *) + path="$1" + shift + break + ;; + esac + done + + if [ "$is_file" == "true" ]; then + path="$(preprocess_file_path "$path")" + curl_ftps_command "$(preprocess_directory_path "$(dirname "$path")")" -s | grep "$(basename "$path")" + else + path="$(preprocess_directory_path "$path")" + curl_ftps_command "$(preprocess_directory_path "$path")" + fi } function bambu_upload() { @@ -96,9 +138,9 @@ function bambu_upload() { curl_ftps_command "$directory" -T "$1" } -function bambu_rmfile() { +function bambu_rm() { local file="$(preprocess_file_path "$1")" - curl_ftps_command "$file" -Q "DELE /$file" + curl_ftps_command "" -Q "DELE /$file" > /dev/null 2>&1 || echo "Failed to delete file $file" } function bambu_print() { @@ -225,14 +267,8 @@ case "$command" in status) bambu_status "$@" ;; - lsdir) - bambu_lsdir "$@" - ;; - upload) - bambu_upload "$@" - ;; - rmfile) - bambu_rmfile "$@" + file) + bambu_file "$@" ;; print) bambu_print "$@"