Skip to content

Commit

Permalink
feat: run the default command if no command is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
masnagam committed Oct 24, 2023
1 parent a666085 commit 5c51342
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
45 changes: 24 additions & 21 deletions recording/recording.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ FOLDER=$DEFAULT_FOLDER
help() {
cat <<EOF >&2
USAGE:
$PROGNAME [options] [list]
$PROGNAME [options] add <program-id>
$PROGNAME [options] delete <program-id>
$PROGNAME [options] list
$PROGNAME [options] show <program-id>
$PROGNAME [options] clear
$PROGNAME [options] clear-all
$PROGNAME [options] start <program-id>
$PROGNAME [options] stop <program-id>
$PROGNAME -h | --help
$PROGNAME -h | --help | help
OPTIONS:
-h, --help
Expand All @@ -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.
Expand Down Expand Up @@ -91,46 +91,54 @@ 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() {
curl "$BASE_URL/api/recording/recorders" -s \
-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() {
Expand Down Expand Up @@ -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'
17 changes: 10 additions & 7 deletions timeshift/timeshift.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ BASE_URL=$DEFAULT_BASE_URL
help() {
cat <<EOF >&2
USAGE:
$PROGNAME [options] status
$PROGNAME [options] [status]
$PROGNAME [options] list <recorder>
$PROGNAME [options] show <recorder> <record-id>
$PROGNAME [options] stream <recorder> <record-id>
Expand All @@ -27,7 +27,7 @@ OPTIONS:
A base URL of mirakc to use.
COMMANDS:
status
status (default command)
Show status of recorders.
list <recorder>
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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

0 comments on commit 5c51342

Please sign in to comment.