# Usage
{{#include ../_logo.html}}
`git-gamble` works with all languages and tools and editors
## How to use ?
To see all available flags and options
```sh
git gamble --help
```
Dash `-` between `git` and `gamble` may be only needed for `--help`
```sh
git-gamble --help
```
There are two ways to run your tests using `git-gamble` :
- by [setting the test command in an environment variable](#environment-variable)
- by [repeating the test command](#repeating-the-test-command)
In both cases,
the test command must exit with a 0 status when there are 0 failed tests,
anything else is considered as a failure
### Environment variable
Setting an environment variable and run only the `git gamble` command
1. Start by setting an environment variable with the test command :
The example below is for running your tests for a Rust project
```sh
export GAMBLE_TEST_COMMAND="cargo test"
```
Use the appropriate command for your shell :
- [Bash](https://man7.org/linux/man-pages/man1/export.1p.html#EXAMPLES)
- [Fish](https://fishshell.com/docs/current/cmds/set.html#examples)
- [PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.5#use-the-variable-syntax)
- [Windows CMD](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/set_1#examples)
1. Write a failing test in your codebase, then :
```sh
git gamble --red
git gamble --fail
```
1. Write the minimum code to make tests pass, then :
```sh
git gamble --green
git gamble --pass
```
1. Refactor your code, then :
```sh
git gamble --refactor
git gamble --pass
```
#### DirEnv
To avoid re-exporting manually the variable at each new terminal, it's recommended to install [DirEnv](https://direnv.net/)
Then add in a `.envrc` file
```sh
export GAMBLE_TEST_COMMAND="cargo test"
```
Then run this command
```sh
direnv allow
```
### Repeating the test command
Typing the `git gamble` command with your test command _repetitively_
1. Write a failing test in your codebase, then :
```sh
git gamble --red -- $YOUR_TEST_COMMAND
```
The example below is for running your tests for a Node.js project that use PNPM
```sh
git gamble --red -- pnpm test
```
1. Write the minimum code to make tests pass, then :
```sh
git gamble --green -- $YOUR_TEST_COMMAND
```
1. Refactor your code, then :
```sh
git gamble --refactor -- $YOUR_TEST_COMMAND
```
### Demo
For more detailed example, view the [demo](demo/index.html)
<div aria-hidden="true">
[](demo/index.html)
</div>