Updated 2015-06-19 13:44:53 by octavsly

general procedures to deals with procedure argument passing, error handling, colors (using VT100 terminal library for TCL).

Source packages: https://github.com/octavsly/octopus

Wiki: https://github.com/octavsly/octopus/wiki. See also info_procedures.tcl script.

Example of usages:
#!/bin/sh
# the next line restarts using -*-Tcl-*-sh \
exec tclsh "$0" ${1+"$@"}

if { [info exists env(OCTOPUS_INSTALL_PATH) ] } {
        lappend auto_path $env(OCTOPUS_INSTALL_PATH)
} else {
        puts "ERROR: Please set environmental variable OCTOPUS_INSTALL_PATH to point to the location of octopus.tcl file"
        exit 1
}

package require octopus 0.1

#...

# BEGIN command line options/arguments parsing

::octopus::add_option --name "--type"                                                      --valid-values "diehard utel poptag" --help-text "Specify the file type from the 3 supported formats."

::octopus::add_option --name "--listfile"
::octopus::add_option --name "--temposync"               --default "false"
::octopus::add_option --name "--corrupt-files"           --default "false"
::octopus::add_option --name "--dump-expanded-file-list" --default "false" --type "boolean"
::octopus::add_option --name "--project-dir"             --default "false"
::octopus::add_option --name "--no-email"                --default "false" --type "boolean"

::octopus::extract_check_options_data

::octopus::abort_on error

# END command line options/arguments parsing

puts "type=$type"
puts "listfile=$listfile"
puts "temposync=$temposync"
puts "corrupt-files=${corrupt-files}"
puts "dump-expanded-file-list=${dump-expanded-file-list}"
puts "project-dir=${project-dir}"
puts "no-email=${no-email}"

If the code above is saved as /tmp/a here are the results of several runs:

  • Asking for automatically generated help
user@pc $ export OCTOPUS_INSTALL_PATH=<path to location of download>
user@pc $ /tmp/a --help

Usage:

  a  --type diehard|utel|poptag --listfile <string> [--temposync <string>] [--corrupt-files <string>] [--dump-expanded-file-list] [--project-dir <string>] [--no-email] [--no-colour] [--debug-level <#>] [--help]

Options:
    --type  diehard|utel|poptag : Specify the file type from the 3 supported formats.
    --listfile  <string>        : No help available. Urge the developer to provide useful information.
    --temposync  <string>       : No help available. Urge the developer to provide useful information. Default value is false.
    --corrupt-files  <string>   : No help available. Urge the developer to provide useful information. Default value is false.
    --dump-expanded-file-list   : No help available. Urge the developer to provide useful information. Default value is false.
    --project-dir  <string>     : No help available. Urge the developer to provide useful information. Default value is false.
    --no-email                  : No help available. Urge the developer to provide useful information. Default value is false.

General Options:
    --no-colour                 : Turns off colourful output (not recommended). Default value is false.
    --debug-level  <#>          : Displays more debug information during the run. Default value is the calling debug level. Default value is 0.
    --help                      : This help message. Default value is false.

  • Wrong invocation due to missing option specified
user@pc $ /tmp/a  --listfile test_list
ERROR:      Option --type is compulsory when calling '/tmp/a' procedure

  • Final correct invocation
user@pc $ /tmp/a  --listfile test_list --type  diehard
type=diehard
listfile=test_list
temposync=false
corrupt-files=false
dump-expanded-file-list=false
project-dir=false
no-email=false