rvmrc_warning 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #!/usr/bin/env bash
  2. __rvmrc_warning()
  3. {
  4. \typeset __rvmrc_warning_path __rvmrc_warning_file
  5. __rvmrc_warning_path="$rvm_user_path/rvmrc_ignored"
  6. case "${1:-help}" in
  7. (list)
  8. __rvmrc_warning_$1 "${2:-}" || return $?
  9. ;;
  10. (check|check_quiet|ignore|reset)
  11. __rvmrc_full_path_to_file "${2:-}" &&
  12. __rvmrc_warning_$1 "${__rvmrc_warning_file:-${2:-}}" ||
  13. return $?
  14. ;;
  15. (help)
  16. rvm_help rvmrc warning
  17. ;;
  18. (*)
  19. rvm_error_help "Unknown subcommand '$1'" rvmrc warning
  20. return 1
  21. ;;
  22. esac
  23. }
  24. __rvmrc_full_path_to_file()
  25. {
  26. if
  27. [[ "$1" == "all.rvmrcs" || "$1" == "allGemfiles" ]]
  28. then
  29. # extra case when managing all
  30. __rvmrc_warning_file="$1"
  31. elif
  32. [[ -d "$1" && -s "$1/.rvmrc" ]]
  33. then
  34. # read full path and append .rvmrc
  35. __rvmrc_warning_file="$( __rvm_cd "$1" >/dev/null 2>&1; pwd )/.rvmrc"
  36. elif
  37. [[ -d "$1" && -s "$1/Gemfile" ]]
  38. then
  39. # read full path and append Gemfile
  40. __rvmrc_warning_file="$( __rvm_cd "$1" >/dev/null 2>&1; pwd )/Gemfile"
  41. elif
  42. [[ -f "$1" || "$1" == *".rvmrc" || "$1" == *"Gemfile" ]]
  43. then
  44. # read dir from file name
  45. __rvmrc_warning_file="$( dirname "$1" )"
  46. # default to current dir if not given in file name
  47. : __rvmrc_warning_file:${__rvmrc_warning_file:=$PWD}
  48. # build full path to file
  49. __rvmrc_warning_file="${__rvmrc_warning_file}/${1##*/}"
  50. else
  51. rvm_warn "Do not know how to handle '$1', please report: https://github.com/rvm/rvm/issues ~ __rvmrc_full_path_to_file"
  52. return 1
  53. fi
  54. }
  55. __rvmrc_warning_list()
  56. {
  57. rvm_log "# List of project files that ignore warnings:"
  58. if [[ -s "$__rvmrc_warning_path" ]]
  59. then \command \cat "$__rvmrc_warning_path"
  60. fi
  61. }
  62. __rvmrc_warning_check()
  63. {
  64. if __rvmrc_warning_check_quiet "$1"
  65. then rvm_log "path '$1' is ignored."
  66. else
  67. \typeset ret=$?
  68. rvm_log "path '$1' is not ignored."
  69. return $ret
  70. fi
  71. }
  72. __rvmrc_warning_check_quiet()
  73. {
  74. [[ -f "$__rvmrc_warning_path" ]] || return $?
  75. \typeset __rvmrc_type
  76. case "$1" in
  77. (all.rvmrcs|allGemfiles) true ;;
  78. (*)
  79. # convert to all<file>s
  80. __rvmrc_type="^all${1##*/}s"
  81. if __rvm_grep "${__rvmrc_type}$" "$__rvmrc_warning_path" >/dev/null
  82. then return 0
  83. fi
  84. ;;
  85. esac
  86. __rvm_grep "^$1$" "$__rvmrc_warning_path" >/dev/null || return $?
  87. }
  88. __rvmrc_warning_ignore()
  89. {
  90. __rvmrc_warning_check_quiet "$1" ||
  91. case "$1" in
  92. (all.rvmrcs|allGemfiles)
  93. echo "$1" >> "$__rvmrc_warning_path"
  94. ;;
  95. (*)
  96. echo "$1" >> "$__rvmrc_warning_path"
  97. ;;
  98. esac
  99. }
  100. __rvmrc_warning_reset()
  101. {
  102. \typeset __rvmrc_type
  103. case "${1:-}" in
  104. (all.rvmrcs|allGemfiles)
  105. if
  106. __rvmrc_warning_check_quiet "$1"
  107. then
  108. __rvm_sed_i "$__rvmrc_warning_path" -e "\#^${1}\$# d" -e '/^$/ d'
  109. __rvmrc_type="${1#all}"
  110. __rvmrc_type="${__rvmrc_type%s}"
  111. __rvm_sed_i "$__rvmrc_warning_path" -e "\#/${__rvmrc_type}\$# d" -e '\#^$# d'
  112. else
  113. rvm_debug "Already removed warning ignore from '$1'."
  114. fi
  115. ;;
  116. (*)
  117. if __rvmrc_warning_check_quiet "$1"
  118. then __rvm_sed_i "$__rvmrc_warning_path" -e "\#^${1}\$# d" -e '\#^$# d'
  119. else rvm_debug "Already removed warning ignore from '$1'."
  120. fi
  121. ;;
  122. esac
  123. }
  124. __rvmrc_warning_display_for_rvmrc()
  125. {
  126. \typeset __rvmrc_warning_path __rvmrc_warning_file
  127. __rvmrc_warning_path="$rvm_user_path/rvmrc_ignored"
  128. if
  129. [[ -t 2 ]] &&
  130. __rvmrc_full_path_to_file "${1:-}" &&
  131. ! __rvmrc_warning_check_quiet "${__rvmrc_warning_file:-${2:-}}"
  132. then
  133. rvm_warn "You are using '.rvmrc', it requires trusting, it is slower and it is not compatible with other ruby managers,
  134. you can switch to '.ruby-version' using 'rvm rvmrc to ruby-version'
  135. or ignore this warning with 'rvm rvmrc warning ignore $1',
  136. '.rvmrc' will continue to be the default project file in RVM 1 and RVM 2,
  137. to ignore the warning for all files run 'rvm rvmrc warning ignore all.rvmrcs'.
  138. "
  139. fi
  140. }
  141. __rvmrc_warning_display_for_Gemfile()
  142. {
  143. \typeset __rvmrc_warning_path __rvmrc_warning_file
  144. __rvmrc_warning_path="$rvm_user_path/rvmrc_ignored"
  145. if
  146. [[ -t 2 ]] &&
  147. __rvmrc_full_path_to_file "${1:-}" &&
  148. ! __rvmrc_warning_check_quiet "${__rvmrc_warning_file:-${2:-}}"
  149. then
  150. rvm_warn "RVM used your Gemfile for selecting Ruby, it is all fine - Heroku does that too,
  151. you can ignore these warnings with 'rvm rvmrc warning ignore $1'.
  152. To ignore the warning for all files run 'rvm rvmrc warning ignore allGemfiles'.
  153. "
  154. fi
  155. }