-
Notifications
You must be signed in to change notification settings - Fork 87
Enhance ability to use template variables #650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 28 commits
5392d36
10b6e3a
666cdea
24b49bf
b275988
fc59ea0
aa23ce3
45c6ffb
b003c52
a966685
754e2da
d0eb0db
7424e13
52a1c9e
4beda25
6845ce3
880bebe
2ff052d
a525cb5
0c2e5c4
5365a1e
11fbbd4
06a3d2a
dc69b5f
0a6db56
40588ef
6d1ad63
f37de7e
03d0767
bc2a78f
3d5c2c3
dd5f764
efdd5e1
e885589
3f65bd2
fd288dd
d1bd7b5
7f11b80
f37bfb6
a41a5a3
ebe408e
6cd1786
d6847dc
7481e6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| config.deactivate_tasks.sh |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| # | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please consider using appropriate indentation level for all comments in the code. It's impossible to follow what the code is doing and the level of indentation when all comments start from the first column. This request applies to all the new functions.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, will do.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, done. Also did |
||
| #----------------------------------------------------------------------- | ||
| # | ||
| # This file defines a function that returns the contents of a bash script/ | ||
| # function with all empty lines, comment lines, and leading and trailing | ||
| # whitespace removed. Arguments are as follows: | ||
| # | ||
| # fp: | ||
| # The relative or full path to the file containing the bash script or | ||
| # function. | ||
| # | ||
| # output_varname_contents: | ||
| # Name of the output variable that will contain the (processed) contents | ||
| # of the file. This is the output of the function. | ||
| # | ||
| #----------------------------------------------------------------------- | ||
| # | ||
| function get_bash_file_contents() { | ||
| # | ||
| #----------------------------------------------------------------------- | ||
| # | ||
| # Save current shell options (in a global array). Then set new options | ||
| # for this script/function. | ||
| # | ||
| #----------------------------------------------------------------------- | ||
| # | ||
| { save_shell_opts; set -u +x; } > /dev/null 2>&1 | ||
| # | ||
| #----------------------------------------------------------------------- | ||
| # | ||
| # Specify the set of valid argument names for this script/function. Then | ||
| # process the arguments provided to this script/function (which should | ||
| # consist of a set of name-value pairs of the form arg1="value1", etc). | ||
| # | ||
| #----------------------------------------------------------------------- | ||
| # | ||
| local valid_args=( \ | ||
| "fp" \ | ||
| "output_varname_contents" \ | ||
| ) | ||
| process_args valid_args "$@" | ||
| # | ||
| #----------------------------------------------------------------------- | ||
| # | ||
| # For debugging purposes, print out values of arguments passed to this | ||
| # script. Note that these will be printed out only if VERBOSE is set to | ||
| # TRUE. | ||
| # | ||
| #----------------------------------------------------------------------- | ||
| # | ||
| print_input_args "valid_args" | ||
| # | ||
| #----------------------------------------------------------------------- | ||
| # | ||
| # Verify that the required arguments to this function have been specified. | ||
| # If not, print out an error message and exit. | ||
| # | ||
| #----------------------------------------------------------------------- | ||
| # | ||
| if [ -z "$fp" ]; then | ||
| print_err_msg_exit "\ | ||
| The argument \"fp\" specifying the relative or full path to the file to | ||
| read was not specified in the call to this function: | ||
| fp = \"$fp\"" | ||
| fi | ||
| # | ||
| #----------------------------------------------------------------------- | ||
| # | ||
| # Declare local variables. | ||
| # | ||
| #----------------------------------------------------------------------- | ||
| # | ||
| local contents \ | ||
| crnt_line | ||
| # | ||
| #----------------------------------------------------------------------- | ||
| # | ||
| # Read in all lines in the file. In doing so: | ||
| # | ||
| # 1) Concatenate any line ending with the bash line continuation character | ||
| # (a backslash) with the following line. | ||
| # 2) Remove any leading and trailing whitespace. | ||
| # | ||
| # Note that these two actions are automatically performed by the "read" | ||
| # utility in the while-loop below. | ||
| # | ||
| #----------------------------------------------------------------------- | ||
| # | ||
| contents="" | ||
| while read crnt_line; do | ||
| contents="${contents}${crnt_line} | ||
| " | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line seems like it needs a line continuation, maybe?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is actually correct; I tested it. It is just adding a newline after appending
This is a bit slower since it calls |
||
| done < "$fp" | ||
| # | ||
| # Strip out any comment and empty lines from contents. | ||
| # | ||
| contents=$( printf "${contents}" | \ | ||
| $SED -r -e "/^#.*/d" `# Remove comment lines.` \ | ||
| -e "/^$/d" `# Remove empty lines.` \ | ||
| ) | ||
| # | ||
| #----------------------------------------------------------------------- | ||
| # | ||
| # Set output variables. | ||
| # | ||
| #----------------------------------------------------------------------- | ||
| # | ||
| printf -v ${output_varname_contents} "${contents}" | ||
| # | ||
| #----------------------------------------------------------------------- | ||
| # | ||
| # Restore the shell options saved at the beginning of this script/function. | ||
| # | ||
| #----------------------------------------------------------------------- | ||
| # | ||
| { restore_shell_opts; } > /dev/null 2>&1 | ||
|
|
||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unclear to me how this test will pass/fail. It certainly wouldn't run for a WE2E test where commands are actually submitted. Is it a smoke test to make sure a var_defns.sh file comes out? Are the contents of that file checked for the right answer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is a test to make sure the templated variables are placed towards the end of var_defns.sh. I actually wrote some other code to make sure that the commands in these variables can be evaluated and executed properly (in as much as it makes sense to evaluate them), and they do. I did not have a good case of how these would be used in an actual application, so I left it at that. If you have a use case we can include as a WE2E test, that would be great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this test run?