Skip to content

Commit

Permalink
Another iteration (#7)
Browse files Browse the repository at this point in the history
- add makefile
- minor improvements
  • Loading branch information
zafarella authored Dec 26, 2017
1 parent 17384e9 commit b128096
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 11 deletions.
41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
BINARY_NAME=envs
BINARY_UNIX=$(BINARY_NAME)_unix
COMMIT_HASH=-X main.GitCommit=$(shell git rev-parse --short HEAD)
BUILT_USER=-X main.BuiltUser=$(shell echo ${USER})
LDFLAGS=-ldflags "$(BUILT_USER) $(COMMIT_HASH)"

all: deps test build
build:
$(GOBUILD) -o $(BINARY_NAME) $(LDFLAGS) -v

test:
$(GOTEST) -v ./...

clean:
$(GOCLEAN)
rm -f $(BINARY_NAME)
rm -f $(BINARY_UNIX)

run:
$(GOBUILD) -o $(BINARY_NAME) -v ./...
./$(BINARY_NAME)
deps:
$(GOGET) -d ./...

build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BINARY_UNIX) -v

darwin:
cd ${BUILD_DIR};
GOOS=darwin GOARCH=${GOARCH} go build ${LDFLAGS} -o ${BINARY}-darwin-${GOARCH} . ;
cd - >/dev/null

windows:
cd ${BUILD_DIR};
GOOS=windows GOARCH=${GOARCH} go build ${LDFLAGS} -o ${BINARY}-windows-${GOARCH}.exe . ;
cd - >/dev/null
1 change: 0 additions & 1 deletion command/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type InitCommand struct {
}

func (c *InitCommand) Run(args []string) int {
// Write your code here
fmt.Println("args = ", args)

osGitUser, err := exec.Command("git", "config", "--get", "user.name").Output()
Expand Down
25 changes: 20 additions & 5 deletions command/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,33 @@ package command

import (
"strings"
//"fmt"
//"gopkg.in/src-d/go-git.v4"
//"gopkg.in/src-d/go-git.v4/storage/memory"
//"gopkg.in/src-d/go-git.v4/plumbing"
)

type ListCommand struct {
Meta
}

func (c *ListCommand) Run(args []string) int {
// Write your code here

// git branch --merged

//r, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
// URL: "https://github.com/zafarella/envs",
//})
//CheckIfError(err)
//
//err = r.Fetch(&git.FetchOptions{
//})
//
//list, err := r.Branches()
//CheckIfError(err)
//
//list.ForEach(func(reference *plumbing.Reference) error {
// fmt.Println(reference.Name())
// return nil
//})
return 0
}

Expand All @@ -22,8 +38,7 @@ func (c *ListCommand) Synopsis() string {

func (c *ListCommand) Help() string {
helpText := `
List branches for the given environment.
List branches for the given environment.
`
return strings.TrimSpace(helpText)
}
22 changes: 21 additions & 1 deletion command/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func askForConfirmation(s string) bool {
reader := bufio.NewReader(os.Stdin)

for {
fmt.Printf("%s [y/n]: ", s)
fmt.Printf("%s [Y/n]: ", s)

response, err := reader.ReadString('\n')
if err != nil {
Expand All @@ -35,3 +35,23 @@ func askForConfirmation(s string) bool {
}
}
}

// CheckIfError should be used to naively panics if an error is not nil.
func CheckIfError(err error) {
if err == nil {
return
}

fmt.Printf("\x1b[31;1m%s\x1b[0m\n", fmt.Sprintf("error: %s", err))
os.Exit(1)
}

// Info should be used to describe the example commands that are about to run.
func Info(format string, args ...interface{}) {
fmt.Printf("\x1b[34;1m%s\x1b[0m\n", fmt.Sprintf(format, args...))
}

// Warning should be used to display a warning
func Warning(format string, args ...interface{}) {
fmt.Printf("\x1b[36;1m%s\x1b[0m\n", fmt.Sprintf(format, args...))
}
6 changes: 3 additions & 3 deletions command/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ func (c *ResetCommand) Run(args []string) int {
red := color.New(color.FgHiRed).PrintfFunc()

if len(args) < 2 {
red("You missing either branch or app name.")
red("You did not provided either branch or app name.")
return 1
}

var app string = args[0]
var envBranch string = args[1]
var app = args[0]
var envBranch = args[1]
if askForConfirmation("This will reset branch " + envBranch + " for " + app + ". Continue?") {
red("Reseting branch %s for %s..", envBranch, app)
/*
Expand Down
1 change: 0 additions & 1 deletion command/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

type VersionCommand struct {
Meta

Name string
Version string
Revision string
Expand Down

0 comments on commit b128096

Please sign in to comment.