Skip to content

Commit

Permalink
completes [#17]
Browse files Browse the repository at this point in the history
  • Loading branch information
zephinzer committed Apr 1, 2019
1 parent 355d1f0 commit 6444d53
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 18 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ start:
fi
start.linux: compile.linux
@$(MAKE) log.debug MSG="running godev for development..."
@$(CURDIR)/bin/godev--linux-amd64 -vv --watch $(CURDIR) --dir $(CURDIR)/dev ${ARGS}
@$(CURDIR)/bin/godev--linux-amd64 -vv --args 'hi,there' --watch $(CURDIR) --dir $(CURDIR)/dev ${ARGS}
start.macos: compile.macos
@$(MAKE) log.debug MSG="running godev for development..."
@$(CURDIR)/bin/godev--darwin-amd64 -vv --watch $(CURDIR) --dir $(CURDIR)/dev ${ARGS}
@$(CURDIR)/bin/godev--darwin-amd64 -vv --args 'hi,there' --watch $(CURDIR) --dir $(CURDIR)/dev ${ARGS}
start.windows: compile.windows
@$(MAKE) log.debug MSG="running godev for development..."
@$(CURDIR)/bin/godev--windows-386.exe -vv --watch $(CURDIR) --dir $(CURDIR)/dev ${ARGS}
@$(CURDIR)/bin/godev--windows-386.exe -vv --args 'hi,there' --watch $(CURDIR) --dir $(CURDIR)/dev ${ARGS}

## installs the dependencies
deps:
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ By default, GoDev will run for live-reload in development. This results in the d

| Flag | Description |
| --- | --- |
| [`--args`](#--args) | Specifies arguments to pass into commands of the final execution group (the application being live-reloaded) |
| [`--dir`](#--dir) | Specifies the working directory |
| [`--env`](#--env) | Specifies an environment variable |
| [`--exec`](#--exec) | Specifies comma-delimited commands |
Expand Down Expand Up @@ -212,6 +213,11 @@ Tells GoDev to keep completely quiet. Only panic level logs are printed before G

#### Configuration

##### `--args`
Specifies the arguments to be passed into the last execution group which should contain the path to your binary.

Default: None

##### `--dir`
Specifies the directory for commands from GoDev to run from.

Expand Down
6 changes: 6 additions & 0 deletions cli_default_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package main
import (
"strings"

shellquote "github.com/kballard/go-shellquote"
"github.com/urfave/cli"
)

func getDefaultFlags() []cli.Flag {
return []cli.Flag{
getFlagBuildOutput(),
getFlagCommandArguments(),
getFlagCommandsDelimiter(),
getFlagEnvVars(),
getFlagExecGroups(),
Expand All @@ -25,8 +27,12 @@ func getDefaultFlags() []cli.Flag {

func getDefaultAction(config *Config) cli.ActionFunc {
return func(c *cli.Context) error {
var err error
config.RunDefault = true
config.BuildOutput = c.String("output")
if config.CommandArguments, err = shellquote.Split(c.String("args")); err != nil {
panic(err)
}
config.CommandsDelimiter = c.String("exec-delim")
config.EnvVars = c.StringSlice("env")
config.ExecGroups = c.StringSlice("exec")
Expand Down
1 change: 1 addition & 0 deletions cli_default_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (s *CLIDefaultHandlerTestSuite) SetupTest() {
func (s *CLIDefaultHandlerTestSuite) Test_getDefaultFlags() {
ensureCLIFlags(s.T(),
[]string{
"args",
"dir",
"env",
"exec-delim",
Expand Down
4 changes: 4 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
// DefaultBuildOutput - default relative path to watch directory to place built binaries in
const DefaultBuildOutput = "bin/app"

// DefaultCommandArguments - default arguments to pass to commands in the last execution group
const DefaultCommandArguments = ""

// DefaultCommandsDelimiter - default string to split --execs into commands with
const DefaultCommandsDelimiter = ","

Expand All @@ -31,6 +34,7 @@ const DefaultRefreshRate = 2 * time.Second
// Config configures the main application entrypoint
type Config struct {
BuildOutput string
CommandArguments ConfigCommaDelimitedString
CommandsDelimiter string
EnvVars ConfigMultiflagString
ExecGroups ConfigMultiflagString
Expand Down
6 changes: 3 additions & 3 deletions data.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// MAKE CHANGES AT ~/app/data/generate AND RUN make generate TO REGENERATE
// THE FOLLOWING FILE
//
// GENERATED BY GO:GENERATE AT 2019-03-23 17:36:49.028176925 +0000 UTC m=+0.005074006
// GENERATED BY GO:GENERATE AT 2019-04-01 23:00:52.748727486 +0800 HKT m=+0.011792104
//
// FILE GENERATED USING ~/app/data/generate.go

Expand All @@ -14,7 +14,7 @@ package main
const Version = "0.5.40"

// Commit is used by godev for reporting the version when installed via 'go get'
const Commit = "48be2b5"
const Commit = "355d1f0"

// DataDockerfile defines the 'Dockerfile' contents when --init is used
// hash:fc3c6491cb0d101ae17e2e68aec4714f
Expand Down Expand Up @@ -249,7 +249,7 @@ const DataGoDotMod = `module app
// MAKE CHANGES AT ~/app/data/generate AND RUN make generate TO REGENERATE
// THE FOLLOWING FILE
//
// GENERATED BY GO:GENERATE AT 2019-03-23 17:36:49.028176925 +0000 UTC m=+0.005074006
// GENERATED BY GO:GENERATE AT 2019-04-01 23:00:52.748727486 +0800 HKT m=+0.011792104
//
// FILE GENERATED USING ~/app/data/generate.go

Expand Down
9 changes: 9 additions & 0 deletions flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ func getFlagBuildOutput() cli.Flag {
}
}

// getFlagCommandArguments provisions --output
func getFlagCommandArguments() cli.Flag {
return cli.StringFlag{
Name: "args",
Usage: "| where <value> is a comma delimited string containing arguments to pass to commands in the final execution group",
Value: DefaultCommandArguments,
}
}

// getFlagCommandsDelimiter provisions --exec-delim
func getFlagCommandsDelimiter() cli.Flag {
return cli.StringFlag{
Expand Down
4 changes: 4 additions & 0 deletions flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func (s *FlagsTestSuite) Test_getFlagBuildOutput() {
ensureFlag(s.T(), getFlagBuildOutput(), cli.StringFlag{}, `^output.*`)
}

func (s *FlagsTestSuite) Test_getFlagCommandArguments() {
ensureFlag(s.T(), getFlagCommandArguments(), cli.StringFlag{}, `^args`)
}

func (s *FlagsTestSuite) Test_getFlagCommandsDelimiter() {
ensureFlag(s.T(), getFlagCommandsDelimiter(), cli.StringFlag{}, `^exec-delim.*`)
}
Expand Down
29 changes: 17 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,32 @@ type GoDev struct {
func (godev *GoDev) Start() {
defer godev.logger.Infof("godev has ended")
godev.logger.Infof("godev has started")
if godev.config.RunVersion || godev.config.RunView {
// do nothing
if godev.config.RunDefault || godev.config.RunTest {
godev.startWatching()
} else if godev.config.RunInit {
godev.initialiseDirectory()
} else {
godev.startWatching()
}
}

func (godev *GoDev) createPipeline() []*ExecutionGroup {
var pipeline []*ExecutionGroup
for _, execGroup := range godev.config.ExecGroups {
for execGroupIndex, execGroup := range godev.config.ExecGroups {
executionGroup := &ExecutionGroup{}
var executionCommands []*Command
commands := strings.Split(execGroup, godev.config.CommandsDelimiter)
for _, command := range commands {
if sections, err := shellquote.Split(command); err != nil {
panic(err)
} else {
arguments := sections[1:]
if execGroupIndex == len(godev.config.ExecGroups)-1 {
arguments = append(arguments, godev.config.CommandArguments...)
}
executionCommands = append(
executionCommands,
InitCommand(&CommandConfig{
Application: sections[0],
Arguments: sections[1:],
Arguments: arguments,
Directory: godev.config.WorkDirectory,
Environment: godev.config.EnvVars,
LogLevel: godev.config.LogLevel,
Expand Down Expand Up @@ -123,17 +125,20 @@ func (godev *GoDev) logWatchModeConfigurations() {
logger.Debugf("refresh interval : %v", config.Rate)
logger.Debugf("execution delim : %s", config.CommandsDelimiter)
logger.Debug("execution groups as follows...")
for egIndex, execGroup := range config.ExecGroups {
logger.Debugf(" %v) %s", egIndex+1, execGroup)
for execGroupIndex, execGroup := range config.ExecGroups {
logger.Debugf(" %v) %s", execGroupIndex+1, execGroup)
commands := strings.Split(execGroup, config.CommandsDelimiter)
for cIndex, command := range commands {
for commandIndex, command := range commands {
sections, err := shellquote.Split(command)
if err != nil {
panic(err)
}
app := sections[0]
args := sections[1:]
logger.Debugf(" %v > %s %v", cIndex+1, app, args)
application := sections[0]
arguments := sections[1:]
if execGroupIndex == len(config.ExecGroups)-1 {
arguments = append(arguments, config.CommandArguments...)
}
logger.Debugf(" %v > %s %v", commandIndex+1, application, arguments)
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,13 @@ func (s *UtilsTestSuite) Test_fileExists() {
func (s *UtilsTestSuite) Test_fileExists_onDirectory() {
assert.False(s.T(), fileExists(getCurrentWorkingDirectory()))
}

func (s *UtilsTestSuite) Test_sliceContainsString() {
testSlice := []string{"a", "b", "c"}
// test the happy path
assert.True(s.T(), sliceContainsString(testSlice, "a"))
// test the sad path
assert.False(s.T(), sliceContainsString(testSlice, "d"))
// test if duplicates might affect searching
assert.False(s.T(), sliceContainsString(testSlice, "aa"))
}

0 comments on commit 6444d53

Please sign in to comment.