#!/bin/dash
#        file: hello_world2
#   copyright: Bernd Schumacher <bernd.schumacher@hpe.com> (2007-2020)
#     license: GNU General Public License, version 3
# description: example "hello world" script with function, debug and check
#     warning: for security, use $(mktmep) instead of /tmp/mylog for ia_logfile
#     warning: Be aware that the interactive step size in this example is only
#              reasonable to summanrized demonstrate shellia features.
#              Read shellia(7) NOTES, to learn about a reasonable size of
#              interactive steps.
#       usage: ./hello_world2 [-d] [-i|-s|-m] [--] <name>

rm -f /tmp/mylog
ia_logfile="/tmp/mylog" . /usr/share/shellia/ia

# say_hello <name>
say_hello()
{
  local name

  { set +x; } 2>/dev/null
  eval "$ia_init"
  ia_add "dbg \"function say_hello called with $# arguments\""
  ia_add "[ $# -eq 1 ] || return 42 # check arguments"
  ia_add "name=\"$1\""
  ia_stdout ".*"
  ia_add "echo \"hello \$name\""
  ia_add "dbg \"function say_hello end\""
  ia -c -x
}

eval "$ia_init"
ia_add "dbg \"main program begin\""
ia_add "[ \"$1\" ] || { ia_err \"Need one name to greet!!!\"; exit 1; }"
ia_stdout "^hello"
ia_add "say_hello <-i> -- $*"
ia_stdout "^please remove Logfile"
ia_add "dbg \"main program end\""
ia -c -x
