From 76acce651dcdbf65095d25a47cecaf50832e5334 Mon Sep 17 00:00:00 2001 From: jayala-29 Date: Fri, 3 Jul 2020 17:31:49 -0700 Subject: [PATCH] `treehouses magazines` (fixes #1589) (#1605) Co-authored-by: dogi --- README.md | 2 +- _treehouses | 10 +- cli.sh | 2 +- {magazine => magazines}/download-hackspace.sh | 0 .../download-helloworld.sh | 0 {magazine => magazines}/download-magpi.sh | 1 - {magazine => magazines}/download-wireframe.sh | 0 modules/help.sh | 2 +- modules/magazine.sh | 58 ------------ modules/magazines.sh | 93 +++++++++++++++++++ package.json | 2 +- tests/magazine/helloworld.bats | 17 ---- tests/{magazine => magazines}/hackspace.bats | 12 +-- tests/magazines/helloworld.bats | 17 ++++ tests/{magazine => magazines}/magpi.bats | 12 +-- tests/{magazine => magazines}/wireframe.bats | 12 +-- tests/test.sh | 2 +- 17 files changed, 138 insertions(+), 104 deletions(-) rename {magazine => magazines}/download-hackspace.sh (100%) rename {magazine => magazines}/download-helloworld.sh (100%) rename {magazine => magazines}/download-magpi.sh (95%) rename {magazine => magazines}/download-wireframe.sh (100%) delete mode 100644 modules/magazine.sh create mode 100644 modules/magazines.sh delete mode 100644 tests/magazine/helloworld.bats rename tests/{magazine => magazines}/hackspace.bats (58%) create mode 100644 tests/magazines/helloworld.bats rename tests/{magazine => magazines}/magpi.bats (58%) rename tests/{magazine => magazines}/wireframe.bats (55%) diff --git a/README.md b/README.md index fd118d39a2..315501ecea 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ inspire [fact|joke|qotd|random] displays quote based on user input convert converts video and audio files gpio displays raspberry pi model and corresponding GPIO ports changelog [view|compare] displays the most recent changes to treehouses -magazine downloads specific magazine issue as a pdf based on user input +magazines downloads specific magazine issue as a pdf based on user input [all|latest|number] resolution sets the screen resolution message gitter sends message to service or sets api/channel info in config file diff --git a/_treehouses b/_treehouses index 82c9cf2821..9a847b54bf 100644 --- a/_treehouses +++ b/_treehouses @@ -422,11 +422,11 @@ treehouses services $line url tor\n" function magazine_cmds { while IFS= read -r line; do - printf "treehouses magazine $line -treehouses magazine $line latest -treehouses magazine $line language -treehouses magazine $line all\n" - done <<< "$(find /usr/lib/node_modules/@treehouses/cli/magazine -type f -printf "%f\n" | grep .sh | sed 's/download-//' | sed 's/.sh//')" + printf "treehouses magazines $line +treehouses magazines $line latest +treehouses magazines $line language +treehouses magazines $line all\n" + done <<< "$(find /usr/lib/node_modules/@treehouses/cli/magazines -type f -printf "%f\n" | grep .sh | sed 's/download-//' | sed 's/.sh//')" } complete -F _treehouses_complete treehouses ./cli.sh diff --git a/cli.sh b/cli.sh index 77449f8637..590d69d26d 100755 --- a/cli.sh +++ b/cli.sh @@ -5,7 +5,7 @@ SCRIPTFOLDER=$(dirname "$SCRIPTPATH") SCRIPTARGS="$*" TEMPLATES="$SCRIPTFOLDER/templates" SERVICES="$SCRIPTFOLDER/services" -MAGAZINE="$SCRIPTFOLDER/magazine" +MAGAZINES="$SCRIPTFOLDER/magazines" CONFIGFILE=/etc/treehouses.conf BASENAME=$(basename "$0") WIFICOUNTRY="US" diff --git a/magazine/download-hackspace.sh b/magazines/download-hackspace.sh similarity index 100% rename from magazine/download-hackspace.sh rename to magazines/download-hackspace.sh diff --git a/magazine/download-helloworld.sh b/magazines/download-helloworld.sh similarity index 100% rename from magazine/download-helloworld.sh rename to magazines/download-helloworld.sh diff --git a/magazine/download-magpi.sh b/magazines/download-magpi.sh similarity index 95% rename from magazine/download-magpi.sh rename to magazines/download-magpi.sh index 032fb10f41..3fc49ceb43 100755 --- a/magazine/download-magpi.sh +++ b/magazines/download-magpi.sh @@ -72,7 +72,6 @@ function number { function language { echo "The default language for MagPi is English" echo "Currently, MagPi also offers some magazines in French, Hebrew, Italian, and Spanish" - echo "You can access these by running: treehouses magazine magpi language [french|hebrew|italian|spanish]" exit 0 } diff --git a/magazine/download-wireframe.sh b/magazines/download-wireframe.sh similarity index 100% rename from magazine/download-wireframe.sh rename to magazines/download-wireframe.sh diff --git a/modules/help.sh b/modules/help.sh index 67f61fc508..b5daf28244 100644 --- a/modules/help.sh +++ b/modules/help.sh @@ -114,7 +114,7 @@ inspire [fact|joke|qotd|random] displays quote based on user input convert converts video and audio files gpio displays raspberry pi model and corresponding GPIO ports changelog [view|compare] displays the most recent changes to treehouses -magazine downloads specific magazine issue as a pdf based on user input +magazines downloads specific magazine issue as a pdf based on user input [all|latest|number] resolution sets the screen resolution message gitter sends message to service or sets api/channel info in config file diff --git a/modules/magazine.sh b/modules/magazine.sh deleted file mode 100644 index 719b78186a..0000000000 --- a/modules/magazine.sh +++ /dev/null @@ -1,58 +0,0 @@ -function magazine() { - checkargn $# 3 - magtype="$1" - req="$2" - lang="$3" - available_mag=0 - if [ -z "$magtype" ]; then - echo "ERROR: no magazine type given" - exit 1 - fi - for file in $MAGAZINE/*; do - if [ "$magtype" = "$(echo "${file##*/}" | sed -e 's/^download-//' -e 's/.sh$//')" ]; then available_mag=1; fi - done - if [ $available_mag = 0 ]; then - echo "Please specify a valid magazine type, these include: magpi, hackspace, wireframe, helloworld" - elif [ "$req" = "" ]; then source $MAGAZINE/download-$magtype.sh && info - elif [ "$req" = "latest" ] || [ "$req" = "all" ] || [[ "$req" =~ ^[0-9]+$ ]] || [[ "$req" = "language" ]]; then - if [[ "$req" = "language" ]]; then - echo "coming soon!" - exit 1 - fi - checkinternet - if [ ! -d "$magtype" ]; then mkdir $magtype; fi - cd $magtype || return - if [[ "$req" =~ ^[0-9]+$ ]]; then source $MAGAZINE/download-$magtype.sh && number - else source $MAGAZINE/download-$magtype.sh && $req; fi - cd .. - echo "Requested issue(s) saved in the $magtype directory if there are no errors" - else - magazine_help - fi -} - -function magazine_help { - echo - echo "Usage: $BASENAME magazine [all|latest|number]" - echo - echo "This downloads the specified issue of a magazine as a pdf with filename #.pdf based on user input" - echo "The MagPi magazine also supports other languages listed above to a limited number of issues" - echo - echo "Example:" - echo - echo " $BASENAME magazine magpi" - echo " This will print out details about the magpi magazine." - echo - echo " $BASENAME magazine magpi all" - echo " This will download all the currently present issues of magpi." - echo - echo " $BASENAME magazine magpi latest" - echo " This will download the latest issue of magpi." - echo - echo " $BASENAME magazine magpi number" - echo " This will download issue [number] of magpi." - echo - echo " $BASENAME magazine magpi language [language_choice] ((coming soon))" - echo " This will download all available [language_choice] issues of magpi." - echo -} diff --git a/modules/magazines.sh b/modules/magazines.sh new file mode 100644 index 0000000000..48685b1471 --- /dev/null +++ b/modules/magazines.sh @@ -0,0 +1,93 @@ +function magazines() { + checkargn $# 3 + magtype="$1" + req="$2" + lang="$3" + available_mag=0 + if [ -z "$magtype" ]; then + echo "ERROR: no magazine type given" + exit 1 + fi + for file in $MAGAZINES/*; do + if [ "$magtype" = "$(echo "${file##*/}" | sed -e 's/^download-//' -e 's/.sh$//')" ]; then available_mag=1; fi + done + if [ $available_mag = 0 ]; then + echo "Please specify a valid magazine type, these include: magpi, hackspace, wireframe, helloworld" + elif [ "$req" = "" ]; then source $MAGAZINES/download-$magtype.sh && info + elif [ "$req" = "latest" ] || [ "$req" = "all" ] || [[ "$req" =~ ^[0-9]+$ ]] || [[ "$req" = "language" ]]; then + if [[ "$req" = "language" ]]; then + echo "coming soon!" + exit 1 + fi + checkinternet + if [ ! -d "$magtype" ]; then mkdir $magtype; fi + cd $magtype || return + if [[ "$req" =~ ^[0-9]+$ ]]; then source $MAGAZINES/download-$magtype.sh && number + else source $MAGAZINES/download-$magtype.sh && $req; fi + cd .. + echo "Requested issue(s) saved in the $magtype directory" + else + magazine_help + fi +} + +function magazine_help { + echo + echo "Usage: $BASENAME magazines [all|latest|number]" + echo + echo "This downloads the specified issue of a magazine as a pdf with filename #.pdf based on user input" + echo + echo "Example:" + echo + echo " $BASENAME magazines magpi" + echo " This will print out details about the magpi magazine." + echo + echo " $BASENAME magazines magpi all" + echo " This will download all the currently present issues of magpi." + echo + echo " $BASENAME magazines magpi latest" + echo " This will download the latest issue of magpi." + echo + echo " $BASENAME magazines magpi number" + echo " This will download issue [number] of magpi." + echo + echo " $BASENAME magazines magpi language [language_choice] ((coming soon))" + echo " This will download all available [language_choice] issues of magpi." + echo + echo " $BASENAME magazines helloworld" + echo " This will print out details about the helloworld magazine." + echo + echo " $BASENAME magazines helloworld all" + echo " This will download all the currently present issues of helloworld." + echo + echo " $BASENAME magazines helloworld latest" + echo " This will download the latest issue of helloworld." + echo + echo " $BASENAME magazines helloworld number" + echo " This will download issue [number] of helloworld." + echo + echo " $BASENAME magazines hackspace" + echo " This will print out details about the hackspace magazine." + echo + echo " $BASENAME magazines hackspace all" + echo " This will download all the currently present issues of hackspace." + echo + echo " $BASENAME magazines hackspace latest" + echo " This will download the latest issue of hackspace." + echo + echo " $BASENAME magazines hackspace number" + echo " This will download issue [number] of hackspace." + echo + echo " $BASENAME magazines wireframe" + echo " This will print out details about the wireframe magazine." + echo + echo " $BASENAME magazines wireframe all" + echo " This will download all the currently present issues of wireframe." + echo + echo " $BASENAME magazines wireframe latest" + echo " This will download the latest issue of wireframe." + echo + echo " $BASENAME magazines wireframe number" + echo " This will download issue [number] of wireframe." + echo +} diff --git a/package.json b/package.json index 0ad19c1b5b..325dc3bda1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@treehouses/cli", - "version": "1.23.0", + "version": "1.23.1", "remote": "2346", "description": "Thin command-line interface for Raspberry Pi low level configuration.", "main": "cli.sh", diff --git a/tests/magazine/helloworld.bats b/tests/magazine/helloworld.bats deleted file mode 100644 index ffae6bb847..0000000000 --- a/tests/magazine/helloworld.bats +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bats -load ../test-helper - -@test "$clinom magazine helloworld" { - run "${clicmd}" magazine helloworld - assert_output -p "HelloWorld is the computing and digital making magazine for educators." -} - -@test "$clinom magazine helloworld latest" { - run "${clicmd}" magazine helloworld latest - assert_success -} - -@test "$clinom magazine helloworld all" { - run "${clicmd}" magazine helloworld all - assert_success -} diff --git a/tests/magazine/hackspace.bats b/tests/magazines/hackspace.bats similarity index 58% rename from tests/magazine/hackspace.bats rename to tests/magazines/hackspace.bats index fb26ea8ee5..d0da3f6ac0 100644 --- a/tests/magazine/hackspace.bats +++ b/tests/magazines/hackspace.bats @@ -1,17 +1,17 @@ #!/usr/bin/env bats load ../test-helper -@test "$clinom magazine hackspace" { - run "${clicmd}" magazine hackspace +@test "$clinom magazines hackspace" { + run "${clicmd}" magazines hackspace assert_output -p "HackSpace magazine is packed with projects for fixers and tinkerers of all abilities. We'll teach you new techniques and give you refreshers on familiar ones, from 3D printing, laser cutting, and woodworking to electronics and Internet of Things." } -@test "$clinom magazine hackspace latest" { - run "${clicmd}" magazine hackspace latest +@test "$clinom magazines hackspace latest" { + run "${clicmd}" magazines hackspace latest assert_success } -@test "$clinom magazine hackspace all" { - run "${clicmd}" magazine hackspace all +@test "$clinom magazines hackspace all" { + run "${clicmd}" magazines hackspace all assert_success } diff --git a/tests/magazines/helloworld.bats b/tests/magazines/helloworld.bats new file mode 100644 index 0000000000..c4c19d0796 --- /dev/null +++ b/tests/magazines/helloworld.bats @@ -0,0 +1,17 @@ +#!/usr/bin/env bats +load ../test-helper + +@test "$clinom magazines helloworld" { + run "${clicmd}" magazines helloworld + assert_output -p "HelloWorld is the computing and digital making magazine for educators." +} + +@test "$clinom magazines helloworld latest" { + run "${clicmd}" magazines helloworld latest + assert_success +} + +@test "$clinom magazines helloworld all" { + run "${clicmd}" magazines helloworld all + assert_success +} diff --git a/tests/magazine/magpi.bats b/tests/magazines/magpi.bats similarity index 58% rename from tests/magazine/magpi.bats rename to tests/magazines/magpi.bats index 173239ff1d..22f338c883 100644 --- a/tests/magazine/magpi.bats +++ b/tests/magazines/magpi.bats @@ -1,17 +1,17 @@ #!/usr/bin/env bats load ../test-helper -@test "$clinom magazine magpi" { - run "${clicmd}" magazine magpi +@test "$clinom magazines magpi" { + run "${clicmd}" magazines magpi assert_output -p "The MagPi is The Official Raspberry Pi magazine. Written by and for the community, it is packed with Raspberry Pi-themed projects, computing and electronics tutorials, how-to guides, and the latest news and reviews." } -@test "$clinom magazine magpi latest" { - run "${clicmd}" magazine magpi latest +@test "$clinom magazines magpi latest" { + run "${clicmd}" magazines magpi latest assert_success } -@test "$clinom magazine magpi all" { - run "${clicmd}" magazine magpi all +@test "$clinom magazines magpi all" { + run "${clicmd}" magazines magpi all assert_success } diff --git a/tests/magazine/wireframe.bats b/tests/magazines/wireframe.bats similarity index 55% rename from tests/magazine/wireframe.bats rename to tests/magazines/wireframe.bats index 3d531a7056..a56b41ff74 100644 --- a/tests/magazine/wireframe.bats +++ b/tests/magazines/wireframe.bats @@ -1,17 +1,17 @@ #!/usr/bin/env bats load ../test-helper -@test "$clinom magazine wireframe" { - run "${clicmd}" magazine wireframe +@test "$clinom magazines wireframe" { + run "${clicmd}" magazines wireframe assert_output -p "Wireframe is a new fortnightly magazine that lifts the lid on video games. In every issue, we'll be looking at how games are made, who makes them, and even guide you through the process of making your own." } -@test "$clinom magazine wireframe latest" { - run "${clicmd}" magazine wireframe latest +@test "$clinom magazines wireframe latest" { + run "${clicmd}" magazines wireframe latest assert_success } -@test "$clinom magazine wireframe all" { - run "${clicmd}" magazine wireframe all +@test "$clinom magazines wireframe all" { + run "${clicmd}" magazines wireframe all assert_success } diff --git a/tests/test.sh b/tests/test.sh index 9736be8796..9d98752482 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -17,7 +17,7 @@ case "$1" in time bats "$@" ;; all) - time bats ./*.bats ./services/*.bats ./magazine/*.bats + time bats ./*.bats ./services/*.bats ./magazines/*.bats ;; services) time bats ./services*