Skip to content

Commit

Permalink
Creating a tgenv version updater to TGENV (cunymatthieu#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
Weyder Ferreira authored Apr 23, 2023
1 parent dc04b91 commit 79d2d0b
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 20 deletions.
97 changes: 79 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,63 @@

![Tests](https://github.com/tgenv/tgenv/actions/workflows/tests.yml/badge.svg?branch=main)

![lixnux](https://img.shields.io/badge/Linux-FCC624?style=for-the-badge&logo=linux&logoColor=black) ![macos](https://img.shields.io/badge/mac%20os-000000?style=for-the-badge&logo=apple&logoColor=white) ![shell](https://img.shields.io/badge/Shell_Script-121011?style=for-the-badge&logo=gnu-bash&logoColor=white)

![tgenvlogo](/assets/tgenv-logo.png)

This project was forked from old project [cunymatthieu/tgenv](https://github.com/cunymatthieu/tgenv). The intention here it's keep the project alive.

[Terragrunt](https://github.com/gruntwork-io/terragrunt) version manager inspired by [tfenv](https://github.com/kamatama41/tfenv)
>[Terragrunt](https://github.com/gruntwork-io/terragrunt) version manager inspired by [tfenv](https://github.com/kamatama41/tfenv) project.

## Support :computer:

## Support
Currently tgenv supports the following OSes
- Mac OS X (64bit)
- Mac OS M1 (arm64)
- Linux (64bit)

## Installation
---

## Summary :bookmark:

1. [Installation](#installation-🔧)
1. [Cloning the repository](#1-cloning-the-repository)
2. [Export PATH](#2-export-to-path)
1. [Bash](#bash)
2. [ZSH](#zsh)
2. [Usage](#usage-▶️)
1. [tgenv install](#tgenv-install)
2. [tgenv use](#tgenv-use)
3. [tgenv uninstall](#tgenv-uninstall)
4. [tgenv list](#tgenv-list)
5. [tgenv list-remote](#tgenv-list-remote)
5. [tgenv upgrade](#tgenv-upgrade)
3. [The terragrunt-version file](#the-terragrunt-version-file-📄)
4. [Environment Variables](#environment-variables-📦)
1. [TGENV_AUTO_INSTALL](#tgenv_auto_install)
2. [TGENV_DEBUG](#tgenv_debug)
5. [Uninstalling](#uninstalling-🚫)
6. [License](#license-👍)


1. Check out tgenv into any path (here is `${HOME}/.tgenv`)
---

## Installation :wrench:

### 1. Cloning the repository

Check out tgenv into any path (here is `${HOME}/.tgenv`)

```bash
$ git clone https://github.com/tgenv/tgenv.git ~/.tgenv
```

2. Add `~/.tgenv/bin` to your `$PATH` any way you like
### 2. Export to PATH

#### Bash

Add `~/.tgenv/bin` to your `$PATH` any way you like

```bash
$ echo 'export PATH="$HOME/.tgenv/bin:$PATH"' >> ~/.bash_profile
Expand All @@ -35,8 +70,24 @@ Currently tgenv supports the following OSes
$ ln -s ~/.tgenv/bin/* /usr/local/bin
```

## Usage
#### ZSH

Add `~/.tgenv/bin` to your `$PATH` any way you like

```bash
$ echo 'export PATH="$HOME/.tgenv/bin:$PATH"' >> ~/.zshrc
```

If you use [Oh My Zsh](ttps://github.com/ohmyzsh/ohmyzsh), after export just run

```bash
$ omz reload
```

## Usage :arrow_forward:

### tgenv install

Install a specific version of terragrunt
`latest` is a syntax to install latest version
`latest:<regex>` is a syntax to install latest version matching regex (used by grep -e)
Expand All @@ -50,6 +101,7 @@ $ tgenv install latest:^0.9
If you use [.terragrunt-version](#terragrunt-version), `tgenv install` (no argument) will install the version written in it.

### tgenv use

Switch a version to use
`latest` is a syntax to use the latest installed version
`latest:<regex>` is a syntax to use latest installed version matching regex (used by grep -e)
Expand All @@ -61,6 +113,7 @@ $ tgenv use latest:^0.10
```

### tgenv uninstall

Uninstall a specific version of terragrunt
`latest` is a syntax to uninstall latest version
`latest:<regex>` is a syntax to uninstall latest version matching regex (used by grep -e)
Expand All @@ -72,6 +125,7 @@ $ tgenv uninstall latest:^0.9
```

### tgenv list

List installed versions

```bash
Expand All @@ -83,6 +137,7 @@ List installed versions
```

### tgenv list-remote

List installable versions

```bash
Expand All @@ -103,7 +158,14 @@ List installable versions
...
```

## .terragrunt-version
### tgenv upgrade

Upgrade the version of TGEnv software to latest version

`$ tgenv upgrade`

## The terragrunt-version file :page_facing_up:

If you put `.terragrunt-version` file on your project root, tgenv detects it and use the version written in it. If the version is `latest` or `latest:<regex>`, the latest matching version currently installed will be selected.

```bash
Expand All @@ -127,11 +189,9 @@ $ terragrunt --version
terragrunt v0.10.3
```

### Environment Variables

#### TGENV
### Environment Variables :package:

##### `TGENV_AUTO_INSTALL`
#### `TGENV_AUTO_INSTALL`

String (Default: true)

Expand All @@ -141,7 +201,7 @@ Should tgenv automatically install terragrunt if the version specified by defaul
TGENV_AUTO_INSTALL=false terragrunt plan
```

##### `TGENV_DEBUG`
#### `TGENV_DEBUG`

Integer (Default: "")

Expand All @@ -150,16 +210,17 @@ Set the debug level for TGENV.
* unset/empty-string: No debug output
* set: Bash execution tracing

## Upgrading
```bash
$ git --git-dir=~/.tgenv/.git pull
```
## Uninstalling :no_entry_sign:

## Uninstalling
Just run:
```bash
$ rm -rf /some/path/to/tgenv
```

## LICENSE
And delete the previous export `$PATH` .

> The uninstall command is under development.
## LICENSE :thumbsup:
- [tgenv itself](https://github.com/tgenv/tgenv/blob/master/LICENSE)
- [tfenv ](https://github.com/kamatama41/tgenv/blob/master/LICENSE) : tfenv mainly uses tfenv's source code
5 changes: 3 additions & 2 deletions libexec/tgenv-help
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ echo "Usage: tgenv <command> [<options>]
Commands:
install Install a specific version of Terragrunt
use Switch a version to use
uninstall Uninstall a specific version of Terragrunt
list List all installed versions
list-remote List all installable versions
uninstall Uninstall a specific version of Terragrunt
upgrade Upgrade TGEnv to latest version
use Switch a version to use
"
32 changes: 32 additions & 0 deletions libexec/tgenv-upgrade
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

##########################################
#
# This script just works like a software
# version updater. It's a shortcut to
# $ git checkout master && git pull
#
##########################################

set -e
[ -n "${TGENV_DEBUG}" ] && set -x
source "${TGENV_ROOT}/libexec/helpers"

TGENV_GITBRANCH=$(git branch)
TGENV_GITCHECKOUTMAIN=$(git -C $TGENV_GITBRANCH checkout main)
TGENV_GITPULL=$(git pull)
TGENV_GITLOG=$(git -C $TGENV_GITBRANCH log -1)
TGENV_GITSTASH=$(git stash)

# If branch it was different of main executes the checkout them
if [$TGENV_GITBRANCH != 'main'];
then
$TGENV_GITSTASH
$TGENV_GITCHECKOUTMAIN
else
$TGENV_GITPULL
fi;

echo $TGENV_GITLOG

exit 0

0 comments on commit 79d2d0b

Please sign in to comment.