From 5c51342b2b6b23d32ae5b95900cb1355e6f41275 Mon Sep 17 00:00:00 2001 From: masnagam Date: Tue, 24 Oct 2023 15:41:22 +0900 Subject: [PATCH] feat: run the default command if no command is specified --- recording/recording.sh | 45 ++++++++++++++++++++++-------------------- timeshift/timeshift.sh | 17 +++++++++------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/recording/recording.sh b/recording/recording.sh index 9187d10..6655735 100644 --- a/recording/recording.sh +++ b/recording/recording.sh @@ -12,15 +12,15 @@ FOLDER=$DEFAULT_FOLDER help() { cat <&2 USAGE: + $PROGNAME [options] [list] $PROGNAME [options] add $PROGNAME [options] delete - $PROGNAME [options] list $PROGNAME [options] show $PROGNAME [options] clear $PROGNAME [options] clear-all $PROGNAME [options] start $PROGNAME [options] stop - $PROGNAME -h | --help + $PROGNAME -h | --help | help OPTIONS: -h, --help @@ -36,15 +36,15 @@ OPTIONS: The name (or relative path) of a folder to store recording files. COMMANDS: + list (default command) + List recording schedules. + add Add a recording schedule with the "manual" tag. delete Delete a recording schedule. - list - List recording schedules. - show Show a recording schedule. @@ -91,33 +91,39 @@ make_json() { EOF } +list() { + curl "$BASE_URL/api/recording/schedules" -sG + exit 0 +} + add() { curl "$BASE_URL/api/recording/schedules" -s \ -X POST \ -H 'Content-Type: application/json' \ -d "$(make_json $1)" + exit 0 } delete() { curl "$BASE_URL/api/recording/schedules/$1" -s \ -X DELETE \ -H 'Content-Type: application/json' -} - -list() { - curl "$BASE_URL/api/recording/schedules" -sG + exit 0 } show() { curl "$BASE_URL/api/recording/schedules/$1" -sG + exit 0 } clear() { curl "$BASE_URL/api/recording/schedules?tag=manual" -s -X DELETE + exit 0 } clear_all() { curl "$BASE_URL/api/recording/schedules" -s -X DELETE + exit 0 } start() { @@ -125,12 +131,14 @@ start() { -X POST \ -H 'Content-Type: application/json' \ -d "$(make_json $1)" + exit 0 } stop() { curl "$BASE_URL/api/recording/recorders/$1" -s \ -X DELETE \ -H 'Content-Type: application/json' + exit 0 } render() { @@ -198,40 +206,35 @@ do FOLDER="$2" shift 2 ;; + 'list') + list | render 'list' + ;; 'add') add $2 | render '' - shift 2 ;; 'delete') delete $2 - shift 2 - ;; - 'list') - list | render 'list' - shift ;; 'show') show $2 | render '' - shift 2 ;; 'clear') clear - shift ;; 'clear-all') clear_all - shift ;; 'start') start $2 - shift 2 ;; 'stop') stop $2 - shift 2 ;; *) - break + help ;; esac done + +# default command +list | render 'list' diff --git a/timeshift/timeshift.sh b/timeshift/timeshift.sh index 11b22ac..eb1fe57 100644 --- a/timeshift/timeshift.sh +++ b/timeshift/timeshift.sh @@ -10,7 +10,7 @@ BASE_URL=$DEFAULT_BASE_URL help() { cat <&2 USAGE: - $PROGNAME [options] status + $PROGNAME [options] [status] $PROGNAME [options] list $PROGNAME [options] show $PROGNAME [options] stream @@ -27,7 +27,7 @@ OPTIONS: A base URL of mirakc to use. COMMANDS: - status + status (default command) Show status of recorders. list @@ -64,18 +64,22 @@ EOF status() { curl "$BASE_URL/api/timeshift" -sG + exit 0 } list() { curl "$BASE_URL/api/timeshift/$1/records" -sG + exit 0 } show() { curl "$BASE_URL/api/timeshift/$1/records/$2" -sG + exit 0 } stream() { curl "$BASE_URL/api/timeshift/$1/records/$2/stream" -sG + exit 0 } render_status() { @@ -138,22 +142,21 @@ do ;; 'status') status | render_status - shift ;; 'list') list $2 | render 'list' - shift 2 ;; 'show') show $2 $3 | render '' - shift 3 ;; 'stream') stream $2 $3 - shift 3 ;; *) - break + help ;; esac done + +# default command +status | render_status