Merge pull request #1685 from NoahGorny/binary-exists

Add _binary_exists and use in github-cli completion
pull/1689/head
Noah Gorny 2020-10-21 11:23:31 +03:00 committed by GitHub
commit c7d67aedb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 1 deletions

View File

@ -2,7 +2,7 @@
cite "about-completion"
about-completion "GitHub CLI completion"
if _command_exists gh; then
if _binary_exists gh; then
if _command_exists brew; then
_log_warning "You don't need github-cli completion enabled if you have system completion enabled"
fi

View File

@ -26,6 +26,17 @@ function _command_exists ()
type "$1" &> /dev/null || (_log_warning "$msg" && return 1) ;
}
function _binary_exists ()
{
_about 'checks for existence of a binary'
_param '1: binary to check'
_param '2: (optional) log message to include when binary not found'
_example '$ _binary_exists ls && echo exists'
_group 'lib'
local msg="${2:-Binary '$1' does not exist!}"
type -P "$1" &> /dev/null || (_log_warning "$msg" && return 1) ;
}
function _make_reload_alias() {
echo "source \${BASH_IT}/scripts/reloader.bash ${1} ${2}"
}

View File

@ -39,6 +39,26 @@ function local_setup {
assert_failure
}
@test "helpers: _binary_exists function exists" {
run type -a _binary_exists &> /dev/null
assert_success
}
@test "helpers: _binary_exists function positive test ls" {
run _binary_exists ls
assert_success
}
@test "helpers: _binary_exists function negative test function" {
run _binary_exists _binary_exists
assert_failure
}
@test "helpers: _binary_exists function negative test" {
run _binary_exists __addfkds_dfdsjdf
assert_failure
}
@test "helpers: bash-it help aliases ag" {
run bash-it help aliases "ag"
assert_line -n 0 "ag='ag --smart-case --pager=\"less -MIRFX'"