Skip to content

Commit

Permalink
treehouses led random (fixes #989) (#1136)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <dogi@users.noreply.github.com>
  • Loading branch information
LordJashin32 and dogi authored Apr 30, 2020
1 parent 95b7ce3 commit 3cd0187
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions _treehouses
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ treehouses led thanksgiving
treehouses led valentine
treehouses led heavymetal
treehouses led stpatricks
treehouses led random
treehouses locale
treehouses log
treehouses log 0
Expand Down
21 changes: 20 additions & 1 deletion modules/led.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ function led {
echo "Green LED: flash 20 times; on 2 sec"
stpatricks > "$LOGFILE"
;;
random)
checkroot
random
return
;;
"")
if [ ! -z "$currentGreen" ]; then
echo -e "$green: $currentGreen"
Expand Down Expand Up @@ -428,10 +433,21 @@ function stpatricks {
led red "$current_red"
}

function random {
rando="$(led_help | grep "led \[" \
| cut -d "[" -f2 \
| cut -d "]" -f1 \
| sed -n '1!p' \
| sed 's/|/\n/g' \
| sed -e '/^random$/d' \
| shuf -n 1)"
led "$rando"
}

function led_help {
echo
echo "Usage: $BASENAME led [green|red] [mode]"
echo " $BASENAME led [dance|thanksgiving|christmas|newyear|lunarnewyear|valentine|carnival|stpatricks]"
echo " $BASENAME led [dance|thanksgiving|christmas|newyear|lunarnewyear|valentine|carnival|stpatricks|random]"
echo
echo "Sets or returns the led mode"
echo
Expand Down Expand Up @@ -508,4 +524,7 @@ function led_help {
echo " $BASENAME led stpatricks"
echo " This will set the mode of the led to stpatricks"
echo
echo " $BASENAME led random"
echo " This will set the mode of the led to one of the above festivities"
echo
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@treehouses/cli",
"version": "1.19.11",
"version": "1.19.12",
"remote": "2251",
"description": "Thin command-line interface for Raspberry Pi low level configuration.",
"main": "cli.sh",
Expand Down
5 changes: 5 additions & 0 deletions tests/led.bats
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,8 @@ load test-helper
run "${clicmd}" led stpatricks
assert_success && assert_output -p 'red led'
}

@test "$clinom led random" {
run "${clicmd}" led random
assert_success
}

0 comments on commit 3cd0187

Please sign in to comment.