Skip to content

Commit

Permalink
Merge pull request #3 from 0jonjo/2-create-show-option-and-check-if-f…
Browse files Browse the repository at this point in the history
…ile-exists

[2] Create show option and check if file exists
  • Loading branch information
0jonjo authored Apr 20, 2024
2 parents 77d57e2 + b7cd1cc commit 214711c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ jobs:

# Runs a single command using the runners shell
- name: Starting tests
run: |
run: |
echo Starting tests
bash tests.sh
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ Replace `<day>` with the day of the week (in German: mon, die, mit, don, frei, s
Output:
Task 'Test' added to Montag.
```
3. To obtain instructions use help.

3. Show the tasks of the current week.

```bash
./woche.sh show
```

Returns the start day of the week and prints the Markdown file with the tasks.

4. To obtain instructions use help.

```bash
./woche.sh help
Expand Down
16 changes: 16 additions & 0 deletions tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ else
fi
check_test_result

# Test the 'create' command when the file already exists
output=$("$woche_script_path" create)
if [[ "$output" == *"The file"*"already exists."* ]]; then
echo "Test 'create' command when the file already exists: PASSED"
else
echo "Test 'create' command when the file already exists: FAILED"
fi

# Test add task to a day command
output=$("$woche_script_path" mon "Test task")
if [[ "$output" == *"Task 'Test task' added to"* ]]; then
Expand All @@ -45,3 +53,11 @@ else
fi
check_test_result

# Test show command
output=$("$woche_script_path" show)
if [[ "$output" == *"Week starts in"* ]]; then
echo "Test 'show' command: PASSED"
else
echo "Test 'show' command: FAILED"
fi
check_test_result
39 changes: 26 additions & 13 deletions woche.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ if [ "$#" -gt 2 ]; then
exit 1
fi

if [ "$1" = "help" ]; then
tips
exit 0
fi

# Find the start_day of the current week
start_day=$(date -d "mon" +%y%m%d)

Expand Down Expand Up @@ -48,14 +43,32 @@ sunday="Sunday"
woche_array=($montag $dienstag $mittwoch $donnerstag $freitag $samstag $sonntag)
week_array=($monday $tuesday $wednesday $thursday $friday $saturday $sunday)

if [ "$1" = "create" ]; then
# Iterate into array to add the days of the week with an empty line below to create the file
for i in "${woche_array[@]}"; do
printf "# %s\n\n" "$i" >> "$start_day.md"
done
echo "The file $start_day.md has been created."
exit 0
fi
case $1 in
create)
if [ -e "$start_day.md" ]; then
echo "The file $start_day.md already exists."
exit 1
fi
for i in "${woche_array[@]}"; do
printf "# %s\n\n" "$i" >> "$start_day.md"
done
echo "The file $start_day.md has been created."
exit 0
;;
show)
if [ ! -e "$start_day.md" ]; then
echo "The file $start_day.md does not exist."
exit 1
fi
printf "Week starts in $start_day.\n\n"
cat "$start_day.md"
exit 0
;;
help)
tips
exit 0
;;
esac

case $1 in
mon)
Expand Down

0 comments on commit 214711c

Please sign in to comment.