Skip to content

Commit

Permalink
Add command to show reminder text at the end
Browse files Browse the repository at this point in the history
  • Loading branch information
norm committed Sep 12, 2021
1 parent 655b01f commit dfb6eaa
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
7 changes: 7 additions & 0 deletions documentation/kitfile.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,10 @@ Available commands are:

Add an entry to the crontab, creating one if necessary. The arguments are
described in more detail in the manual: run `man 5 crontab`.

* remind _TEXT_

Adds text to be output at the end of the run, rather than showing it
immediately. Useful for showing manual actions needed (eg. allowing an
application to use Accessibility features) without them being buried
among the entire output of a run.
11 changes: 11 additions & 0 deletions kitout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ magenta="\e[35m"
reset="\e[0m"

errors_occured=0
remind_file=$( mktemp '/tmp/kitout.remind.XXXXX' )


function main {
Expand All @@ -38,6 +39,11 @@ function main {
process_kitfile "$argument"
done

if [ "$(stat -f'%z' $remind_file)" -gt 0 ]; then
section "REMINDERS"
cat $remind_file
fi

[ $errors_occured -gt 0 ] && exit 1
exit 0
}
Expand Down Expand Up @@ -127,6 +133,7 @@ function process_kitfile {
clone) clone_repository $argument ;;
brewfile) brewfile "$argument" ;;
install) install_file $argument ;;
remind) remind "$argument" ;;

cron_entry) add_to_crontab "$argument" ;;

Expand Down Expand Up @@ -280,4 +287,8 @@ EOF
crontab "$tab"
}

function remind {
echo "$*" >> $remind_file
}

main "$@"
5 changes: 4 additions & 1 deletion tests/10.kitfile_syntax.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ reset=$'\e'[0m
@test output_commands {
run ./kitout.sh tests/parsing.kitfile
echo "$output"
echo "${#lines[@]} lines."

[ ${#lines[@]} = 7 ]
[ ${#lines[@]} = 9 ] # this format skips blank lines
[ "${lines[0]}" == " Hello world." ]
[ "${lines[1]}" == "${cyan} Debug output is formatted and coloured.${reset}" ]
[ "${lines[2]}" == " Indented commands work." ]
[ "${lines[3]}" == "${cyan} ${reset}" ]
[ "${lines[4]}" == " " ]
[ "${lines[5]}" == "${green}=== A section header ==========================================================${reset}" ]
[ "${lines[6]}" == "${green}===============================================================================${reset}" ]
[ "${lines[7]}" == "${green}=== REMINDERS =================================================================${reset}" ]
[ "${lines[8]}" == "This text is only shown at the end of a run." ]
}

@test unknown_command {
Expand Down
2 changes: 2 additions & 0 deletions tests/parsing.kitfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# comments (lines that begin with a hash) and blank lines are ignored

remind This text is only shown at the end of a run.

echo Hello world.
debug Debug output is formatted and coloured.

Expand Down

0 comments on commit dfb6eaa

Please sign in to comment.