diff --git a/bambu.sh b/bambu.sh index 0e63e36..08faff8 100755 --- a/bambu.sh +++ b/bambu.sh @@ -86,51 +86,9 @@ function bambu_status() { mqtt_command '{"pushing": { "sequence_id": 1, "command": "pushall"}, "user_id":"1234567890"}' } -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_lsdir() { + local directory="$(preprocess_directory_path "$1")" + curl_ftps_command "$directory" } function bambu_upload() { @@ -138,9 +96,9 @@ function bambu_upload() { curl_ftps_command "$directory" -T "$1" } -function bambu_rm() { +function bambu_rmfile() { local file="$(preprocess_file_path "$1")" - curl_ftps_command "" -Q "DELE /$file" > /dev/null 2>&1 || echo "Failed to delete file $file" + curl_ftps_command "$file" -Q "DELE /$file" } function bambu_print() { @@ -267,8 +225,14 @@ case "$command" in status) bambu_status "$@" ;; - file) - bambu_file "$@" + lsdir) + bambu_lsdir "$@" + ;; + upload) + bambu_upload "$@" + ;; + rmfile) + bambu_rmfile "$@" ;; print) bambu_print "$@"