Skip to content

Commit

Permalink
Lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gopinath-langote committed Aug 21, 2019
1 parent 5c59050 commit 21fbe18
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 7 deletions.
7 changes: 6 additions & 1 deletion cmd/config/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package config

import (
"errors"
"gopkg.in/yaml.v3"
"io/ioutil"
"os"

"gopkg.in/yaml.v3"
)

// ReadFile returns OneBuildConfiguration file content as string.
func ReadFile() (string, error) {
if _, err := os.Stat(OneBuildConfigFileName); os.IsNotExist(err) {
return "", errors.New("no '" + OneBuildConfigFileName + "' file found in current directory")
Expand All @@ -18,6 +20,7 @@ func ReadFile() (string, error) {
return string(yamlFile), nil
}

// IsConfigFilePresent return whether the config file present or not
func IsConfigFilePresent() bool {
if _, err := os.Stat(OneBuildConfigFileName); err == nil {
return true
Expand All @@ -28,6 +31,8 @@ func IsConfigFilePresent() bool {
}
}

// WriteConfigFile writes config to the file
// If there is an error, it will be of type *Error.
func WriteConfigFile(configuration OneBuildConfiguration) error {
yamlData, _ := yaml.Marshal(&configuration)
content := string(yamlData)
Expand Down
8 changes: 7 additions & 1 deletion cmd/config/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@ package config

import (
"errors"
"strings"

"github.com/gopinath-langote/1build/cmd/utils"
"gopkg.in/yaml.v3"
"strings"
)

// OneBuildConfigFileName one global declaration of config file name
var OneBuildConfigFileName = "1build.yaml"

// OneBuildConfiguration is a representation of yaml configuration as struct
type OneBuildConfiguration struct {
Project string `yaml:"project"`
Before string `yaml:"before,omitempty"`
After string `yaml:"after,omitempty"`
Commands []map[string]string `yaml:"commands"`
}

// LoadOneBuildConfiguration returns the config from file as struct.
// If there is an error, it will be of type *Error.
func LoadOneBuildConfiguration() (OneBuildConfiguration, error) {
var configuration OneBuildConfiguration
fileContent, err := ReadFile()
Expand All @@ -41,6 +46,7 @@ commands:
return configuration, nil
}

// PrintConfiguration prints the configuration to the console
func PrintConfiguration(oneBuildConfiguration OneBuildConfiguration) {
utils.Println(utils.DASH())
utils.Println("project: " + oneBuildConfiguration.Project)
Expand Down
4 changes: 3 additions & 1 deletion cmd/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package exec

import (
"errors"

"github.com/codeskyblue/go-sh"
"github.com/gopinath-langote/1build/cmd/config"
"github.com/gopinath-langote/1build/cmd/utils"
)

func ExecuteCommandAndExit(commands ...string) {
// ExecuteCommands executes given command with before and after is present
func ExecuteCommands(commands ...string) {
configuration, err := config.LoadOneBuildConfiguration()
if err != nil {
utils.PrintErr(err)
Expand Down
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ var rootCmd = &cobra.Command{
if len(args) < 1 {
listCmd.Run(cmd, args)
} else {
exec.ExecuteCommandAndExit(args...)
exec.ExecuteCommands(args...)
}
},
}

// Execute entrypoint for cobra app
func Execute() {
if err := rootCmd.Execute(); err != nil {
utils.PrintErr(err)
Expand Down
7 changes: 4 additions & 3 deletions cmd/unset.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package cmd

import (
"regexp"

"github.com/gopinath-langote/1build/cmd/config"
"github.com/gopinath-langote/1build/cmd/utils"
"regexp"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -49,9 +50,9 @@ This will update the current project configuration file.`,
if index == -1 {
utils.Println("Command '" + commandName + "' not found")
return
} else {
configuration.Commands = removeCommandByIndex(configuration, index)
}

configuration.Commands = removeCommandByIndex(configuration, index)
_ = config.WriteConfigFile(configuration)
},
}
Expand Down
5 changes: 5 additions & 0 deletions cmd/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@ import (
"os"
)

// DASH return dashes with fixed lenght
func DASH() string {
return "--------------------------------------------------"
}

// Println prints text on the console
func Println(text string) {
fmt.Println(text)
}

// PrintErr prints error on the console
func PrintErr(err error) {
fmt.Println(err)
}

// ExitError exit the program with non success code
func ExitError() {
os.Exit(1)
}

// SliceIndex find the index of element matching given predicate
func SliceIndex(limit int, predicate func(i int) bool) int {
for i := 0; i < limit; i++ {
if predicate(i) {
Expand Down
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ require (
github.com/pmezard/go-difflib v1.0.0
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.3
<<<<<<< HEAD
github.com/stretchr/testify v1.4.0
=======
github.com/stretchr/testify v1.3.0
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586 // indirect
golang.org/x/lint v0.0.0-20190409202823-959b441ac422 // indirect
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 // indirect
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // indirect
golang.org/x/text v0.3.2 // indirect
golang.org/x/tools v0.0.0-20190821162956-65e3620a7ae7 // indirect
>>>>>>> Lint fix
gopkg.in/yaml.v3 v3.0.0-20190709130402-674ba3eaed22
)
18 changes: 18 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,26 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
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/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/lint v0.0.0-20190409202823-959b441ac422 h1:QzoH/1pFpZguR8NrRHLcO6jKqfv2zpuSqZLgdm7ZmjI=
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190821162956-65e3620a7ae7 h1:PVCvyir09Xgta5zksNZDkrL+eSm/Y+gQxRG3IfqNQ3A=
golang.org/x/tools v0.0.0-20190821162956-65e3620a7ae7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down

0 comments on commit 21fbe18

Please sign in to comment.