add doc for contributing more tools

This commit is contained in:
Kunal Dabir 2019-07-24 17:56:00 +05:30
parent 197dce1d03
commit bdf7c2ffe6
2 changed files with 14 additions and 2 deletions

View File

@ -180,6 +180,14 @@ On machines that don't even have `has` installed, your project's `.hasrc` is hon
3. Adding support for more commands
4. Adding more features to `has`
## Adding more tools
If the command you wish to include supports any of `-v`, `--version`, `-version`, `version`, `-V` then you can find
corresponding function which can be called to check presence and extract version. However, for many tools version
extraction may not work and you will need to add custom parsing of command's output. The `has` script is commented
to guide developers about what needs to be done to add more tools.
## Adding Features
If you are contributing a feature, please ensure to check current tests. Add test cases for your feature. Tests are

8
has
View File

@ -1,13 +1,15 @@
#!/usr/bin/env bash
## source: https://github.com/kdabir/has
## To add more tools, search for "__detect" function in this file
## Important so that version is not extracted for failed commands (not found)
set -o pipefail
readonly BINARY_NAME="has"
readonly VERSION="v1.4.0"
## constant - symbols for success failure
## constants - symbols for success failure
readonly txtreset="$(tput sgr0)"
readonly txtbold="$(tput bold)"
readonly txtblack="$(tput setaf 0)"
@ -34,10 +36,12 @@ KO=0
## Regex to extract simple version - extracts numeric sem-ver style versions
REGEX_SIMPLE_VERSION="([[:digit:]]+\.?){2,3}"
## RC file can contain commands to be tested
## name of RC file that can contain list of tools to be checked
RC_FILE=".hasrc"
# try to extract version by executing "${1}" with "${2}" arg
# command name to be executed is dynamically passed to this function as ${1}
# arg to ${1} is passed in ${2}
__dynamic_detect(){
cmd="${1}"
params="${2}"