Skip to content

Commit

Permalink
treehouses magazines (fixes #1589) (#1605)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <dogi@users.noreply.github.com>
  • Loading branch information
jayala-29 and dogi authored Jul 4, 2020
1 parent af1613c commit 76acce6
Show file tree
Hide file tree
Showing 17 changed files with 138 additions and 104 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ inspire [fact|joke|qotd|random] displays quote based on user input
convert <input file> <output file> 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 <hackspace|magpi|wireframe> downloads specific magazine issue as a pdf based on user input
magazines <hackspace|magpi|wireframe> downloads specific magazine issue as a pdf based on user input
<helloworld> [all|latest|number]
resolution <cea|dmt [modes]> sets the screen resolution
message gitter <apikey|sendto> sends message to service or sets api/channel info in config file
Expand Down
10 changes: 5 additions & 5 deletions _treehouses
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion magazine/download-magpi.sh → magazines/download-magpi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion modules/help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ inspire [fact|joke|qotd|random] displays quote based on user input
convert <input file> <output file> 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 <hackspace|magpi|wireframe> downloads specific magazine issue as a pdf based on user input
magazines <hackspace|magpi|wireframe> downloads specific magazine issue as a pdf based on user input
<helloworld> [all|latest|number]
resolution <cea|dmt [modes]> sets the screen resolution
message gitter <apikey|sendto> sends message to service or sets api/channel info in config file
Expand Down
58 changes: 0 additions & 58 deletions modules/magazine.sh

This file was deleted.

93 changes: 93 additions & 0 deletions modules/magazines.sh
Original file line number Diff line number Diff line change
@@ -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 <helloworld|hackspace|magpi|wireframe> [all|latest|number]"
echo
echo "This downloads the specified issue of a magazine as a pdf with filename <mag_type>#.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
}
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.23.0",
"version": "1.23.1",
"remote": "2346",
"description": "Thin command-line interface for Raspberry Pi low level configuration.",
"main": "cli.sh",
Expand Down
17 changes: 0 additions & 17 deletions tests/magazine/helloworld.bats

This file was deleted.

12 changes: 6 additions & 6 deletions tests/magazine/hackspace.bats → tests/magazines/hackspace.bats
Original file line number Diff line number Diff line change
@@ -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
}
17 changes: 17 additions & 0 deletions tests/magazines/helloworld.bats
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 6 additions & 6 deletions tests/magazine/magpi.bats → tests/magazines/magpi.bats
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 6 additions & 6 deletions tests/magazine/wireframe.bats → tests/magazines/wireframe.bats
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down

0 comments on commit 76acce6

Please sign in to comment.