pyenv/libexec/rbenv-help

114 lines
3.1 KiB
Text
Raw Normal View History

#!/usr/bin/env bash
set -e
[ -n "$RBENV_DEBUG" ] && set -x
2011-08-10 13:53:24 +00:00
# content from single commented line marked with a word such as "Usage" or "Summary"
extract_line() {
grep "^# ${1}:" "$2" | head -1 | cut -d ' ' -f3-
}
# content of multiple consecutive commented lines starting with a word such as "Help"
extract_section() {
sed -En "/^# ${1}: /,/^[^#]/s/^# ?//p" "$2" | sed "1s/${1}: //"
}
# print aligned command names with help summary
print_summary() {
if [ ! -h "$1" ]; then
local summary=$(extract_line Summary "$1")
if [ -n "$summary" ]; then
local name=$(basename "$1")
echo "${name#rbenv-}" | awk '{ printf " %-14s ", $1 }'
echo -n $summary
echo
else
return 1
fi
fi
}
print_help() {
local usage="$(extract_line Usage "$1")"
local halp="$(extract_section Help "$1")"
[ -z "$halp" ] && halp="$(extract_line Summary "$1")"
if [ -n "$usage" ]; then
echo usage: $usage
[ -n "$halp" ] && echo && echo "$halp"
else
echo "Sorry, this command isn't documented yet." >&2
return 1
fi
}
print_summaries() {
for command in $1; do
print_summary "$(command -v rbenv-"$command")"
done
}
2011-08-10 13:53:24 +00:00
print_set_version() {
2011-08-10 14:23:43 +00:00
echo "<version> should be a string matching a Ruby version known by rbenv."
local versions="$(rbenv-versions --bare)"
if [ -z "$versions" ]; then
echo "There are currently no Ruby versions installed for rbenv."
else
echo "The currently installed Ruby versions are:"
echo "$versions" | sed 's/^/ /'
fi
echo
echo "The special version string 'system' will use your default system Ruby."
2011-08-10 13:53:24 +00:00
}
case "$1" in
"") echo "usage: rbenv <command> [<args>]
Some useful rbenv commands are:
$(print_summaries "commands rehash global local shell version versions which whence")
2011-08-10 13:53:24 +00:00
2011-09-28 15:59:02 +00:00
See 'rbenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/sstephenson/rbenv#readme"
2011-08-10 13:53:24 +00:00
;;
2011-08-18 19:32:33 +00:00
global) echo "usage: rbenv global <version>
2011-08-10 13:53:24 +00:00
2011-08-18 19:32:33 +00:00
Sets the global Ruby version. You can override the global version at
any time by setting a directory-specific version with \`rbenv local'
or by setting the RBENV_VERSION environment variable.
2011-08-10 13:53:24 +00:00
$(print_set_version)"
;;
local) echo "usage: rbenv local <version>
2011-09-28 15:21:57 +00:00
rbenv local --unset
2011-08-10 13:53:24 +00:00
2011-08-10 14:23:43 +00:00
Sets the local directory-specific Ruby version by writing the version
name to a file named '.rbenv-version'.
When you run a Ruby command, rbenv will look for an '.rbenv-version'
file in the current directory and each parent directory. If no such
2011-08-18 19:32:33 +00:00
file is found in the tree, rbenv will use the global Ruby version
specified with \`rbenv global', or the version specified in the
2011-08-10 14:23:43 +00:00
RBENV_VERSION environment variable.
2011-08-10 13:53:24 +00:00
2011-09-28 15:21:57 +00:00
$(print_set_version)"
;;
shell) echo "usage: rbenv shell <version>
rbenv shell --unset
Sets a shell-specific Ruby version by setting the 'RBENV_VERSION'
environment variable in your shell. This version overrides both
project-specific versions and the global version.
2011-08-10 13:53:24 +00:00
$(print_set_version)"
;;
2011-09-28 15:59:02 +00:00
*)
command_path="$(command -v "rbenv-$1" || true)"
if [ -n "$command_path" ]; then
print_help "$command_path"
2011-09-28 15:59:02 +00:00
else
echo "rbenv: no such command \`$1'" >&2
exit 1
2011-09-28 15:59:02 +00:00
fi
2011-08-10 13:53:24 +00:00
esac