Skip to content

Commit

Permalink
Merge pull request #17 from perriea/dev-0.1.2
Browse files Browse the repository at this point in the history
Dev 0.1.2
  • Loading branch information
perriea authored Jun 10, 2017
2 parents 794769a + 9e5e2cb commit 0e0aab8
Show file tree
Hide file tree
Showing 70 changed files with 7,576 additions and 1,123 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ _testmain.go
*.test
*.prof

.vscode/settings.json
tfversion*
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.8.1-alpine
FROM golang:1.8.3-alpine

ENV tfversion_path /go/src/github.com/perriea/tfversion/
ENV terraform_path /root/terraform/bin
Expand All @@ -23,4 +23,4 @@ VOLUME ['/root/.aws', '/root/.ssh']

WORKDIR /root/repo

RUN tfversion install 0.9.4
RUN tfversion install --version 0.9.6
33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,32 @@ Functional for all versions.
## Build Project

- [Install Golang](https://golang.org/doc/install) (add var ENV),
- [Install Govendor](https://github.com/kardianos/govendor),
- Build `go build .`,
- Build `go build` or `go get github.com/perriea/tfversion`,
- Add in your `.bashrc` (Linux) or `.bash_profile` : `export PATH=$PATH:~/terraform/bin`

## Commands

``` shell
~ tfversion help
tfversion v0.1.2

Usage:

tfversion <command> [option]

Options:

-v, --version Show version and check update

Commands:

help Display help informations
install Install new versions or switch.
uninstall Uninstall local version of Terraform
list List online or offline version of terraform
test Test provider cloud (AWS)
```

## Docker

### Require
Expand All @@ -23,16 +45,9 @@ Functional for all versions.
Pull image `docker pull perriea/tfversion`.
Execute command in the terminal : `docker run -it -v ~/.aws:/root/.aws -v ~/.ssh:/root/.ssh perriea/tfversion sh`.

## Roadmap

- Install script.

And other things ...

## Dependancies

- [kardianos/govendor](https://github.com/kardianos/govendor),
- [fatih/color](https://github.com/fatih/color),
- [google/go-github](https://github.com/google/go-github),
- [aws/aws-sdk-go](https://github.com/aws/aws-sdk-go) (modules: Session, EC2, AWSErr).

Expand Down
44 changes: 0 additions & 44 deletions cloud/cloud.go

This file was deleted.

153 changes: 153 additions & 0 deletions command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package main

import (
"fmt"
"os"

"github.com/mkideal/cli"
"github.com/perriea/tfversion/github"
"github.com/perriea/tfversion/terraform/cloud/aws"
"github.com/perriea/tfversion/terraform/init"
"github.com/perriea/tfversion/terraform/install"
"github.com/perriea/tfversion/terraform/list"
"github.com/perriea/tfversion/terraform/uninstall"
)

var help = cli.HelpCommand("display help informations")
var tfversion = "0.1.2"

// root command
type rootT struct {
cli.Helper
Version bool `cli:"v,version" usage:"show version and check update"`
}

var root = &cli.Command{
Desc: fmt.Sprintf("tfversion v%s \n\n\033[1mUsage:\033[0m\n\n tfversion <command> [option]", tfversion),
Argv: func() interface{} { return new(rootT) },
OnRootBefore: func(ctx *cli.Context) error {
tfinit.CreateTree()
return nil
},
Fn: func(ctx *cli.Context) error {
argv := ctx.Argv().(*rootT)

// AutoHelper
if argv.Help || len(os.Args) == 1 {
ctx.WriteUsage()
return nil
}

if argv.Version {
fmt.Printf("tfversion v%s\n\n", tfversion)

// Show if the last version
lastrelease, release := tfgithub.Lastversion(tfversion)
if !lastrelease && release != nil {
fmt.Printf("Your version is out of date ! The latest version is %s. You can update by downloading from Github (%s).", *release.TagName, *release.HTMLURL)
}
return nil
}
return nil
},
}

// install command
type installT struct {
cli.Helper
Version string `cli:"*v,version" usage:"install or switch version"`
}

var install = &cli.Command{
Name: "install",
Desc: "install new versions or switch.",
Argv: func() interface{} { return new(installT) },
OnBefore: func(ctx *cli.Context) error {
tfinit.CreateTree()
return nil
},
Fn: func(ctx *cli.Context) error {
argv := ctx.Argv().(*installT)

tfinstall.Run(argv.Version)
return nil
},
}

// uninstall command
type uninstallT struct {
cli.Helper
All bool `cli:"a,all" usage:"delete all version (tmp)"`
Version string `cli:"!v,version" usage:"Delete version (tmp)"`
}

var uninstall = &cli.Command{
Name: "uninstall",
Desc: "uninstall local version of Terraform",
Argv: func() interface{} { return new(uninstallT) },
OnBefore: func(ctx *cli.Context) error {
tfinit.CreateTree()
return nil
},
Fn: func(ctx *cli.Context) error {
argv := ctx.Argv().(*uninstallT)

if argv.All {
tfuninstall.All()
}

if argv.Version != "" {
tfuninstall.Uniq(argv.Version)
}

return nil
},
}

// list command
type listT struct {
cli.Helper
On bool `cli:"!on,online" usage:"list online version"`
Off bool `cli:"off,offline" usage:"list offline version"`
}

var list = &cli.Command{
Name: "list",
Desc: "list online or offline version of terraform",
Argv: func() interface{} { return new(listT) },
OnBefore: func(ctx *cli.Context) error {
tfinit.CreateTree()
return nil
},
Fn: func(ctx *cli.Context) error {
argv := ctx.Argv().(*listT)

if argv.On {
tflist.ListOn()
} else {
tflist.ListOff()
}
return nil
},
}

// test command
type testT struct {
cli.Helper
Aws bool `cli:"*aws,amazon" usage:"test connection to AWS"`
//Gcp bool `cli:"*gcp,google" usage:"test connection to GCP"`
}

var test = &cli.Command{
Name: "test",
Desc: "test provider cloud (AWS)",
Argv: func() interface{} { return new(testT) },
Fn: func(ctx *cli.Context) error {
argv := ctx.Argv().(*testT)

if argv.Aws {
tfaws.TestConnect()
}
return nil
},
}
50 changes: 7 additions & 43 deletions error/error.go
Original file line number Diff line number Diff line change
@@ -1,50 +1,14 @@
package tferror

import (
"errors"
"fmt"

"github.com/fatih/color"
)

var (
// Errors
info *color.Color
good *color.Color
warn *color.Color
fatal *color.Color
err error
// Errors
err error
)

func init() {
info = color.New(color.FgBlue, color.Bold)
good = color.New(color.FgGreen, color.Bold)
warn = color.New(color.FgYellow, color.Bold)
fatal = color.New(color.FgRed, color.Bold)
}

func Run(level int, message string) {

err = errors.New(message)
if err != nil {
switch level {
case 0:
info.Println(err)
case 1:
good.Println(err)
case 2:
warn.Println(err)
case 3:
fatal.Println(err)
default:
fmt.Println(err)
}
}
}

func Panic(err error) {
// Panic : Show fatal errors
func Panic(err error) {

if err != nil {
panic(err)
}
if err != nil {
panic(err)
}
}
47 changes: 0 additions & 47 deletions help.go

This file was deleted.

Loading

0 comments on commit 0e0aab8

Please sign in to comment.