Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Windows Support #178

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
vendor/
.1build
1build
1build.exe
dist/
!1build.yaml
!1build.yaml
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: go
os:
- linux
- osx
- windows
go:
- 1.12.x
env:
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ brew install gopinath-langote/one-build/one-build
```console
1build unset lint test build
```
### Delete configuration

- Delete with confirmation prompt
```console
1build delete
```

- Delete without confirmation
```console
1build delete --force
```

### Using `before` and `after` commands
Consider that your project requires some environment variables to set before running any
Expand Down
36 changes: 10 additions & 26 deletions cmd/utils/printer.go
Original file line number Diff line number Diff line change
@@ -1,60 +1,44 @@
package utils

import (
"fmt"
"strings"

"github.com/logrusorgru/aurora"
"github.com/fatih/color"
)

// Dash return dashes with fixed length - 72
func Dash() string {
return strings.Repeat("-", MaxOutputWidth)
}

// OneBuildColor represents type for color enum
type OneBuildColor int

const (
// CYAN is 1build's default color standard
CYAN OneBuildColor = 0
CYAN color.Attribute = color.FgCyan

// RED is used in failure messages
RED OneBuildColor = 1
RED color.Attribute = color.FgHiRed
)

// Style represents type for text formatting
type Style struct {
Color OneBuildColor
Color color.Attribute
Bold bool
}

// CPrintln prints the text with given formatting style with newline
func CPrintln(text string, style Style) {
CPrint(text, style)
fmt.Println()
format(style).Println(text)
}

// CPrint prints the text with given formatting style
func CPrint(text string, style Style) {
formattedText := colorize(text, style)
formattedText = bold(formattedText, style)
fmt.Print(formattedText.String())
format(style).Print(text)
}

func bold(formattedText aurora.Value, style Style) aurora.Value {
func format(style Style) *color.Color {
formatter := color.New(style.Color)
if style.Bold {
return formattedText.Bold()
}
return formattedText
}

func colorize(text string, style Style) aurora.Value {
var coloredText aurora.Value
if style.Color == CYAN {
coloredText = aurora.BrightCyan(text)
} else {
coloredText = aurora.BrightRed(text)
formatter = formatter.Add(color.Bold)
}
return coloredText
return formatter
}
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ go 1.12
require (
github.com/codegangsta/inject v0.0.0-20140425184007-37d7f8432a3e // indirect
github.com/codeskyblue/go-sh v0.0.0-20170112005953-b097669b1569
github.com/fatih/color v1.7.0
github.com/kr/pretty v0.1.0 // indirect
github.com/logrusorgru/aurora v0.0.0-20190803045625-94edacc10f9b
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.10 // indirect
github.com/spf13/cobra v0.0.5
github.com/stretchr/testify v1.4.0
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
Expand Down
12 changes: 10 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwc
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
Expand All @@ -20,9 +22,12 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/logrusorgru/aurora v0.0.0-20190803045625-94edacc10f9b h1:PMbSa9CgaiQR9NLlUTwKi+7aeLl3GG5JX5ERJxfQ3IE=
github.com/logrusorgru/aurora v0.0.0-20190803045625-94edacc10f9b/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
Expand All @@ -46,6 +51,9 @@ github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljT
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191008105621-543471e840be h1:QAcqgptGM8IQBC9K/RC4o+O9YmqEm0diQn9QmZw/0mU=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
Expand Down
11 changes: 9 additions & 2 deletions testing/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"testing"

utils2 "github.com/gopinath-langote/1build/cmd/utils"
Expand All @@ -12,7 +14,7 @@ import (
"github.com/gopinath-langote/1build/testing/utils"
)

var binaryName = "1build"
var binaryName string
var binaryPath string
var testDirectory string

Expand All @@ -39,10 +41,15 @@ func TestAll(t *testing.T) {
}

func TestMain(m *testing.M) {
if runtime.GOOS == "windows" {
binaryName = "1build.exe"
} else {
binaryName = "1build"
}
testDir, _ := utils.CreateTempDir()
testDirectory = testDir

binaryPath = testDir + "/" + binaryName
binaryPath = filepath.Join(testDir, binaryName)
buildBinary(binaryPath)

fmt.Println(utils2.Dash() + "\nBinary Path:- '" + binaryPath + "'\n" + utils2.Dash())
Expand Down
3 changes: 2 additions & 1 deletion testing/fixtures/command_delete_fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fixtures

import (
"os"
"path/filepath"
"testing"

"github.com/gopinath-langote/1build/testing/def"
Expand All @@ -27,7 +28,7 @@ func shouldDeleteConfigFile(feature string) Test {
return utils.CreateConfigFile(dir, "project: Sample Project\ncommands:\n")
},
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
return assertFileNotExists(t, dir+"/"+def.ConfigFileName)
return assertFileNotExists(t, filepath.Join(dir, def.ConfigFileName))
},
}
}
Expand Down
5 changes: 3 additions & 2 deletions testing/fixtures/command_init_fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fixtures

import (
"io/ioutil"
"path/filepath"
"testing"

"github.com/gopinath-langote/1build/testing/def"
Expand All @@ -27,8 +28,8 @@ commands:
Name: "shouldInitialiseNewProject",
CmdArgs: []string{"init", "--name", "trial"},
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
filePath := dir + "/" + def.ConfigFileName
assert.FileExists(t, dir+"/"+def.ConfigFileName)
filePath := filepath.Join(dir, def.ConfigFileName)
assert.FileExists(t, filePath)
content, _ := ioutil.ReadFile(filePath)
return assert.Contains(t, string(content), expectedOutput)
},
Expand Down
3 changes: 2 additions & 1 deletion testing/fixtures/command_list_fixtures.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package fixtures

import (
"testing"

"github.com/gopinath-langote/1build/testing/utils"
"github.com/stretchr/testify/assert"
"testing"
)

func featureListTestData() []Test {
Expand Down
22 changes: 12 additions & 10 deletions testing/fixtures/command_set_fixtures.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package fixtures

import (
"io/ioutil"
"path/filepath"
"testing"

"github.com/gopinath-langote/1build/testing/def"
"github.com/gopinath-langote/1build/testing/utils"
"github.com/stretchr/testify/assert"
"io/ioutil"
"testing"
)

func featureSetTestsData() []Test {
Expand Down Expand Up @@ -43,8 +45,8 @@ commands:
return utils.CreateConfigFile(dir, defaultFileContent)
},
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
filePath := dir + "/" + def.ConfigFileName
assert.FileExists(t, dir+"/"+def.ConfigFileName)
filePath := filepath.Join(dir, def.ConfigFileName)
assert.FileExists(t, filePath)
content, _ := ioutil.ReadFile(filePath)
return assert.Contains(t, string(content), expectedOutput)
},
Expand Down Expand Up @@ -72,8 +74,8 @@ commands:
return utils.CreateConfigFile(dir, defaultFileContent)
},
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
filePath := dir + "/" + def.ConfigFileName
assert.FileExists(t, dir+"/"+def.ConfigFileName)
filePath := filepath.Join(dir, def.ConfigFileName)
assert.FileExists(t, filePath)
content, _ := ioutil.ReadFile(filePath)
return assert.Contains(t, string(content), expectedOutput)
},
Expand Down Expand Up @@ -127,8 +129,8 @@ commands:
return utils.CreateConfigFile(dir, defaultFileContent)
},
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
filePath := dir + "/" + def.ConfigFileName
assert.FileExists(t, dir+"/"+def.ConfigFileName)
filePath := filepath.Join(dir, def.ConfigFileName)
assert.FileExists(t, filePath)
content, _ := ioutil.ReadFile(filePath)
return assert.Contains(t, string(content), expectedOutput)
},
Expand Down Expand Up @@ -157,8 +159,8 @@ commands:
return utils.CreateConfigFile(dir, defaultFileContent)
},
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
filePath := dir + "/" + def.ConfigFileName
assert.FileExists(t, dir+"/"+def.ConfigFileName)
filePath := filepath.Join(dir, def.ConfigFileName)
assert.FileExists(t, filePath)
content, _ := ioutil.ReadFile(filePath)
return assert.Contains(t, string(content), expectedOutput)
},
Expand Down
34 changes: 18 additions & 16 deletions testing/fixtures/command_unset_fixtures.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package fixtures

import (
"io/ioutil"
"path/filepath"
"testing"

"github.com/gopinath-langote/1build/testing/def"
"github.com/gopinath-langote/1build/testing/utils"
"github.com/stretchr/testify/assert"
"io/ioutil"
"testing"
)

func featureUnsetTestsData() []Test {
Expand Down Expand Up @@ -47,8 +49,8 @@ commands: []
return utils.CreateConfigFile(dir, defaultFileContent)
},
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
filePath := dir + "/" + def.ConfigFileName
assert.FileExists(t, dir+"/"+def.ConfigFileName)
filePath := filepath.Join(dir, def.ConfigFileName)
assert.FileExists(t, filePath)
content, _ := ioutil.ReadFile(filePath)
return assert.Exactly(t, expectedOutput, string(content))
},
Expand Down Expand Up @@ -124,8 +126,8 @@ commands: []
return utils.CreateConfigFile(dir, defaultFileContent)
},
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
filePath := dir + "/" + def.ConfigFileName
assert.FileExists(t, dir+"/"+def.ConfigFileName)
filePath := filepath.Join(dir, def.ConfigFileName)
assert.FileExists(t, filePath)
content, _ := ioutil.ReadFile(filePath)
return assert.Exactly(t, expectedOutput, string(content))
},
Expand Down Expand Up @@ -153,8 +155,8 @@ commands: []
return utils.CreateConfigFile(dir, defaultFileContent)
},
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
filePath := dir + "/" + def.ConfigFileName
assert.FileExists(t, dir+"/"+def.ConfigFileName)
filePath := filepath.Join(dir, def.ConfigFileName)
assert.FileExists(t, filePath)
content, _ := ioutil.ReadFile(filePath)

testResult := assert.Contains(t, actualOutput, "Following command(s) not found: missingCmd") &&
Expand Down Expand Up @@ -188,8 +190,8 @@ commands:
return utils.CreateConfigFile(dir, defaultFileContent)
},
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
filePath := dir + "/" + def.ConfigFileName
assert.FileExists(t, dir+"/"+def.ConfigFileName)
filePath := filepath.Join(dir, def.ConfigFileName)
assert.FileExists(t, filePath)
content, _ := ioutil.ReadFile(filePath)

testResult := assert.Contains(t, actualOutput, "Following command(s) not found: missingCmd, missingCmd2") &&
Expand Down Expand Up @@ -220,8 +222,8 @@ commands: []
return utils.CreateConfigFile(dir, defaultFileContent)
},
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
filePath := dir + "/" + def.ConfigFileName
assert.FileExists(t, dir+"/"+def.ConfigFileName)
filePath := filepath.Join(dir, def.ConfigFileName)
assert.FileExists(t, filePath)
content, _ := ioutil.ReadFile(filePath)

testResult := assert.Contains(t, actualOutput, "Following command(s) not found: missingCmd") &&
Expand Down Expand Up @@ -252,8 +254,8 @@ commands: []
return utils.CreateConfigFile(dir, defaultFileContent)
},
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
filePath := dir + "/" + def.ConfigFileName
assert.FileExists(t, dir+"/"+def.ConfigFileName)
filePath := filepath.Join(dir, def.ConfigFileName)
assert.FileExists(t, filePath)
content, _ := ioutil.ReadFile(filePath)
return assert.Exactly(t, expectedOutput, string(content))
},
Expand All @@ -280,8 +282,8 @@ commands: []
return utils.CreateConfigFile(dir, defaultFileContent)
},
Assertion: func(dir string, actualOutput string, t *testing.T) bool {
filePath := dir + "/" + def.ConfigFileName
assert.FileExists(t, dir+"/"+def.ConfigFileName)
filePath := filepath.Join(dir, def.ConfigFileName)
assert.FileExists(t, filePath)
content, _ := ioutil.ReadFile(filePath)
return assert.Exactly(t, expectedOutput, string(content))
},
Expand Down
Loading