Skip to content

Commit

Permalink
Allow multiple run arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
VojtechVitek committed Jan 8, 2017
1 parent 7860c40 commit 1b384ca
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
15 changes: 14 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,29 @@ package main

import (
"flag"
"fmt"

"github.com/pressly/fresh/runner"
)

type flagStringSlice []string

func (f *flagStringSlice) String() string {
return fmt.Sprintf("%v", *f)
}

func (f *flagStringSlice) Set(value string) error {
*f = append(*f, value)
return nil
}

func main() {
var watchList, excludeList runner.Multiflag

configPath := flag.String("c", "", "config file path")
buildArgs := flag.String("b", "", "build command line arguments")
runArgs := flag.String("r", "", "run command line arguments")
var runArgs flagStringSlice
flag.Var(&runArgs, "r", "run command line arguments")
buildPath := flag.String("p", "", "root path - package that will be built & ran")
outputBinary := flag.String("o", "", "output (built) binary location")
tmpPath := flag.String("t", "", "tmp path")
Expand Down
2 changes: 1 addition & 1 deletion runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func run() bool {
runnerLog("Running...")

cmd := exec.Command(settings.OutputBinary, settings.RunArgs)
cmd := exec.Command(settings.OutputBinary, settings.RunArgs...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

Expand Down
10 changes: 4 additions & 6 deletions runner/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type config struct {
ConfigPath string `toml:"config_path"`
TmpPath string `toml:"tmp_path"`
BuildArgs string `toml:"build_args"`
RunArgs string `toml:"run_args"`
RunArgs []string `toml:"run_args"`
BuildLog string `toml:"build_log"`
ValidExtensions []string `toml:"valid_ext"`
BuildDelay int32 `toml:"build_delay"`
Expand All @@ -40,7 +40,7 @@ var (
ConfigPath: "./runner.conf",
TmpPath: "./tmp",
BuildArgs: "",
RunArgs: "",
RunArgs: []string{},
BuildLog: "runner-build-errors.log",
ValidExtensions: []string{".go", ".tpl", ".tmpl", ".html"},
BuildDelay: 600,
Expand Down Expand Up @@ -79,7 +79,7 @@ var (
}
)

func initSettings(confFile, buildArgs, runArgs, buildPath, outputBinary, tmpPath *string, watchList, excludeList Multiflag) error {
func initSettings(confFile, buildArgs *string, runArgs []string, buildPath, outputBinary, tmpPath *string, watchList, excludeList Multiflag) error {
defer buildPaths()

if *confFile != "" {
Expand All @@ -96,9 +96,7 @@ func initSettings(confFile, buildArgs, runArgs, buildPath, outputBinary, tmpPath
if *buildArgs != "" {
settings.BuildArgs = *buildArgs
}
if *runArgs != "" {
settings.RunArgs = *runArgs
}
settings.RunArgs = []string(runArgs)
if *buildPath != "" {
settings.Root = *buildPath
}
Expand Down
2 changes: 1 addition & 1 deletion runner/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func initLogFuncs() {

// Start watches for file changes in the root directory.
// After each file system event it builds and (re)starts the application.
func Start(confFile, buildArgs, runArgs, buildPath, outputBinary, tmpPath *string, watchList, excludeList Multiflag) {
func Start(confFile, buildArgs *string, runArgs []string, buildPath, outputBinary, tmpPath *string, watchList, excludeList Multiflag) {
os.Setenv("DEV_RUNNER", "1")
initLimit()
err := initSettings(confFile, buildArgs, runArgs, buildPath, outputBinary, tmpPath, watchList, excludeList)
Expand Down

0 comments on commit 1b384ca

Please sign in to comment.