bash3boilerplate icon indicating copy to clipboard operation
bash3boilerplate copied to clipboard

Question regarding embedding script

Open damianoneill opened this issue 6 years ago • 0 comments

Hi, is there a reason why the following won't work?

$ cat make.sh
#!/usr/bin/env bash

read -r -d '' __usage <<-'EOF' || true
  -p --print_deps  Print dependencies
  -c --clean       Clean project
  -b --build       Build project
  -t --test        Run tests
  -v               Enable verbose mode, print script as it is executed
  -d --debug       Enables debug mode
  -h --help        This page
  -n --no-color    Disable color output
EOF

read -r -d '' __helptext <<-'EOF' || true # exits non-zero when EOF encountered
 This is a script to support the build of Healthbot Projects, it is intended to be used by all projects 
 and provide required boilerplate functions
EOF

source main.sh

# print_deps mode
if [[ "${arg_p:?}" == "1" ]]; then
    info "Print dependencies"
fi

# clean mode
if [[ "${arg_c:?}" == "1" ]]; then
    info "Clean project"
fi

# build mode
if [[ "${arg_b:?}" == "1" ]]; then
    info "Build project"
fi

# test mode
if [[ "${arg_t:?}" == "1" ]]; then
    info "Running Tests"
fi

I've left main.sh as is, other than commenting out the Validation and Runtime sections at the bottom of the file.

./make.sh -p
2019-09-05 21:32:42 UTC [     info] Print dependencies

But the following results in no output.

./make.sh -h

I was expecting that the help mode below in main.sh would work

# help mode
if [[ "${arg_h:?}" == "1" ]]; then
  # Help exists with code 1
  help "Help using ${0}"
fi

The rationale for this approach, rather than updating main.sh, is that I can pull the latest main.sh (with fixes / new features) and use with minimal changes.

Any help, much appreciated.

damianoneill avatar Sep 05 '19 21:09 damianoneill