mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 09:38:16 -07:00
Merge pull request #498 from asdf-vm/install-ignore-comments
Make install command ignore comments
This commit is contained in:
commit
5d409821aa
@ -40,7 +40,7 @@ install_local_tool_versions() {
|
||||
local asdf_versions_path
|
||||
asdf_versions_path=$(find_tool_versions)
|
||||
if [ -f "${asdf_versions_path}" ]; then
|
||||
while IFS= read -r tool_line || [ -n "$tool_line" ]; do
|
||||
while IFS= read -r tool_line; do
|
||||
IFS=' ' read -r -a tool_info <<< "$tool_line"
|
||||
local tool_name
|
||||
tool_name=$(echo "${tool_info[0]}" | xargs)
|
||||
@ -50,7 +50,7 @@ install_local_tool_versions() {
|
||||
if ! [[ -z "$tool_name" || -z "$tool_version" ]]; then
|
||||
install_tool_version "$tool_name" "$tool_version"
|
||||
fi
|
||||
done < "$asdf_versions_path"
|
||||
done <<<"$(strip_tool_version_comments "$asdf_versions_path")"
|
||||
else
|
||||
echo "Either specify a tool & version in the command"
|
||||
echo "OR add .tool-versions file in this directory"
|
||||
|
13
lib/utils.sh
13
lib/utils.sh
@ -574,6 +574,19 @@ shim_plugin_versions() {
|
||||
fi
|
||||
}
|
||||
|
||||
strip_tool_version_comments() {
|
||||
local tool_version_path="$1"
|
||||
|
||||
while IFS= read -r tool_line || [ -n "$tool_line" ]; do
|
||||
# Remove whitespace before pound sign, the pound sign, and everything after it
|
||||
new_line="$(echo "$tool_line" | cut -f1 -d"#" | sed -e 's/[[:space:]]*$//')"
|
||||
|
||||
# Only print the line if it is not empty
|
||||
if [[ -n "$new_line" ]]; then
|
||||
echo "$new_line"
|
||||
fi
|
||||
done < "$tool_version_path"
|
||||
}
|
||||
|
||||
asdf_run_hook() {
|
||||
local hook_name=$1
|
||||
|
@ -153,3 +153,12 @@ EOM
|
||||
run asdf install dummy 1.0
|
||||
[ "$output" == "HEY 1.0 FROM dummy" ]
|
||||
}
|
||||
|
||||
@test "install_command skips comments in .tool-versions file" {
|
||||
cd $PROJECT_DIR
|
||||
echo -n '# dummy 1.2' > ".tool-versions"
|
||||
run asdf install
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" == "" ]
|
||||
[ ! -f $ASDF_DIR/installs/dummy/1.2/version ]
|
||||
}
|
||||
|
@ -314,3 +314,51 @@ teardown() {
|
||||
[ "$output" = $(pwd)/foo ]
|
||||
rm -f foo bar
|
||||
}
|
||||
|
||||
@test "strip_tool_version_comments removes lines that only contain comments" {
|
||||
cat <<EOF > test_file
|
||||
# comment line
|
||||
ruby 2.0.0
|
||||
EOF
|
||||
run strip_tool_version_comments test_file
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "ruby 2.0.0" ]
|
||||
}
|
||||
@test "strip_tool_version_comments removes lines that only contain comments even with missing newline" {
|
||||
echo -n "# comment line" > test_file
|
||||
run strip_tool_version_comments test_file
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "" ]
|
||||
}
|
||||
|
||||
@test "strip_tool_version_comments removes trailing comments on lines containing version information" {
|
||||
cat <<EOF > test_file
|
||||
ruby 2.0.0 # inline comment
|
||||
EOF
|
||||
run strip_tool_version_comments test_file
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "ruby 2.0.0" ]
|
||||
}
|
||||
|
||||
@test "strip_tool_version_comments removes trailing comments on lines containing version information even with missing newline" {
|
||||
echo -n "ruby 2.0.0 # inline comment" > test_file
|
||||
run strip_tool_version_comments test_file
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "ruby 2.0.0" ]
|
||||
}
|
||||
|
||||
@test "strip_tool_version_comments removes all comments from the version file" {
|
||||
cat <<EOF > test_file
|
||||
ruby 2.0.0 # inline comment
|
||||
# comment line
|
||||
erlang 18.2.1 # inline comment
|
||||
EOF
|
||||
expected="$(cat <<EOF
|
||||
ruby 2.0.0
|
||||
erlang 18.2.1
|
||||
EOF
|
||||
)"
|
||||
run strip_tool_version_comments test_file
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "$expected" ]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user