2017-08-28 17:41:32 +02:00
# has
2014-03-04 23:16:26 +01:00
2017-10-14 08:58:53 +02:00
`has` checks presence of various command line tools on the path and also reports their installed version
2014-03-04 23:16:26 +01:00
2018-01-31 05:00:14 +01:00
[![Build Status ](https://travis-ci.org/kdabir/has.svg?branch=master )](https://travis-ci.org/kdabir/has)
2018-02-03 22:52:36 +01:00
[![Open Source Helpers ](https://www.codetriage.com/kdabir/has/badges/users.svg )](https://www.codetriage.com/kdabir/has)
2018-01-31 05:00:14 +01:00
2018-04-08 19:03:10 +02:00
[![demo ](demo.svg )](demo.svg)
2015-03-02 05:28:18 +01:00
## How ?
2014-03-04 23:16:26 +01:00
2018-11-17 06:21:49 +01:00
[Install ](#installing ) the `has` script. There is no dependency apart from `bash` itself
2014-03-04 23:16:26 +01:00
2017-08-29 08:31:11 +02:00
$ has node npm java git gradle
2017-08-28 17:41:32 +02:00
✔ node 8.2.1
✔ npm 5.3.0
✔ java 1.8.0
✔ git 2.14.1
✔ gradle 4.0.1
2014-03-04 23:16:26 +01:00
2017-08-31 16:59:01 +02:00
If everything is good `has` exits with status code `0` . The status code
2017-08-29 08:31:11 +02:00
reflects number of commands **not found** on your path.
$ has node go javac
✔ node 8.2.1
✔ go 1.8.3
✘ javac
And echo the status:
$ echo $?
1
2017-08-28 18:57:04 +02:00
## Installing
2018-11-17 06:21:49 +01:00
`has` is a single bash script that does it all. Just [download ](https://raw.githubusercontent.com/kdabir/has/master/has ) the script and make it available on your `$PATH` . However, to make it even simpler, just follow *one* of these methods.
### Cloning the Repo
Just execute the following command in terminal, it clones has repo and install it in your path
2017-08-28 18:57:04 +02:00
2017-08-29 08:31:11 +02:00
git clone https://github.com/kdabir/has.git & & cd has & & make install
2018-11-17 06:21:49 +01:00
To update just do a `git pull` and `make install` .
### Directly writing to file
curl -sL https://git.io/_has > /usr/local/bin/has
This command is safe to be called multiple times as well. (to update `has` )
### Directly running of the internet
2017-08-29 08:31:11 +02:00
If you are lazy, you can run `has` directly off the internet as well:
2017-08-28 18:57:04 +02:00
2017-08-29 14:47:59 +02:00
curl -sL https://git.io/_has | bash -s git node npm
2017-08-28 18:57:04 +02:00
✔ git 2.14.1
✔ node 8.2.1
✔ npm 5.3.0
2018-11-17 06:21:49 +01:00
**ProTip**: if that's too much of typing every time, setup an alias in your `.bashrc` /`.zshrc` file:
2017-08-28 18:57:04 +02:00
2017-08-29 14:47:59 +02:00
alias has="curl -sL https://git.io/_has | bash -s"
2017-08-28 18:57:04 +02:00
2017-08-31 16:59:01 +02:00
And use it
2017-08-28 18:57:04 +02:00
$ has git
✔ git 2.14.1
2017-09-12 06:14:51 +02:00
## command not understood by has?
Let's say `$ has foobar` returns `foobar not understood` , because `has` may not have whitelisted `foobar` .
In such cases, pass `HAS_ALLOW_UNSAFE=y has foobar` . This is should still check for existance of `foobar` and tries to detect version as well.
2017-08-28 18:57:04 +02:00
2017-10-14 08:58:53 +02:00
2018-11-16 12:20:36 +01:00
## the `.hasrc` file
`has` looks for `.hasrc` file in the directory from where `has` command is issued. This file can contain commands that `has`
will check for. List one command per line. Lines starting with `#` are treated as comments.
Following is example of `.hasrc` file:
```
# tools
git
curl
# interpreters
ruby
node
```
When `has` is run in dir containing this file, it produces:
```
$ has
✔ git 2.19.1
✔ curl 7.54.0
✔ ruby 2.3.1
✔ node 10.7.0
```
Also, CLI arguments passed to `has` are additive to `.hasrc` file. For example, in the same dir, if the following command is fired,
`has` checks for both commands passed from cli args and provided in `.hasrc` file.
```
$ has java
✔ java 11.0.1
✔ git 2.19.1
✔ curl 7.54.0
✔ ruby 2.3.1
✔ node 10.7.0
```
2018-11-17 06:21:49 +01:00
**Pro Tip**: commit `.hasrc` file in root of your project. This can work as a quick check for confirming presence all command
2018-11-16 12:49:46 +01:00
line tools required to build and run your project.
2018-11-17 06:21:49 +01:00
On machines that don't even have `has` installed, your project's `.hasrc` is honored by this command:
2018-11-16 12:49:46 +01:00
`curl -sL https://git.io/_has | bash -s`
2018-11-16 14:11:00 +01:00
> take a look at [.hasrc](https://github.com/kdabir/has/blob/master/.hasrc) file of this repo
2018-11-16 12:49:46 +01:00
2017-10-14 08:58:53 +02:00
## Contributing
2017-08-28 19:20:44 +02:00
2017-08-31 11:17:13 +02:00
2017-10-14 08:58:53 +02:00
1. Star the repo, tweet about it, spread the word
2. Update the documentation (i.e. the README file)
3. Adding support for more commands
4. Adding more features to `has`
2017-08-31 11:17:13 +02:00
2017-10-14 08:58:53 +02:00
2018-11-16 12:20:36 +01:00
## Adding Features
If you are contributing a feature, please ensure to check current tests. Add test cases for your feature. Tests are
2018-11-16 14:13:35 +01:00
executed using the excellent [bats ](https://github.com/bats-core/bats-core ) testing framework. Add tests and run `make test`
2018-11-16 12:20:36 +01:00
2018-11-16 14:13:35 +01:00
Raise the PR and make sure the tests pass on [Travis-CI ](https://travis-ci.org/kdabir/has ).
2018-11-16 12:20:36 +01:00
2018-11-16 14:13:35 +01:00
#### ♥