params support fixed
This commit is contained in:
parent
f95bbbe537
commit
7d68650706
6
main.go
6
main.go
|
@ -69,12 +69,6 @@ func main() {
|
||||||
},
|
},
|
||||||
Action: func(p *cli.Context) error {
|
Action: func(p *cli.Context) error {
|
||||||
y := r.New(p)
|
y := r.New(p)
|
||||||
if p.NArg() > 0 {
|
|
||||||
y.Projects[0].Params = make([]string, p.NArg() - 1)
|
|
||||||
for i := 1; i < p.NArg(); i++ {
|
|
||||||
y.Projects[0].Params[i - 1] = p.Args().Get(i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return handle(y.Fast(p))
|
return handle(y.Fast(p))
|
||||||
},
|
},
|
||||||
Before: func(c *cli.Context) error {
|
Before: func(c *cli.Context) error {
|
||||||
|
|
|
@ -19,8 +19,45 @@ type Config struct {
|
||||||
Projects []Project
|
Projects []Project
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// New method puts the cli params in the struct
|
||||||
|
func New(params *cli.Context) *Config {
|
||||||
|
return &Config{
|
||||||
|
file: AppFile,
|
||||||
|
Version: AppVersion,
|
||||||
|
Projects: []Project{
|
||||||
|
{
|
||||||
|
Name: nameFlag(params),
|
||||||
|
Path: filepath.Clean(params.String("path")),
|
||||||
|
Build: params.Bool("build"),
|
||||||
|
Bin: boolFlag(params.Bool("no-bin")),
|
||||||
|
Run: boolFlag(params.Bool("no-run")),
|
||||||
|
Fmt: boolFlag(params.Bool("no-fmt")),
|
||||||
|
Params: argsParam(params),
|
||||||
|
Watcher: Watcher{
|
||||||
|
Paths: watcherPaths,
|
||||||
|
Ignore: watcherIgnores,
|
||||||
|
Exts: watcherExts,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// argsParam parse one by one the given argumentes
|
||||||
|
func argsParam(params *cli.Context) []string {
|
||||||
|
argsN := params.NArg()
|
||||||
|
if argsN > 0 {
|
||||||
|
var args []string
|
||||||
|
for i := 0; i <= argsN-1; i++ {
|
||||||
|
args = append(args, params.Args().Get(i))
|
||||||
|
}
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// NameParam check the project name presence. If empty takes the working directory name
|
// NameParam check the project name presence. If empty takes the working directory name
|
||||||
func nameParam(params *cli.Context) string {
|
func nameFlag(params *cli.Context) string {
|
||||||
var name string
|
var name string
|
||||||
if params.String("name") == "" && params.String("path") == "" {
|
if params.String("name") == "" && params.String("path") == "" {
|
||||||
return WorkingDir()
|
return WorkingDir()
|
||||||
|
@ -33,7 +70,7 @@ func nameParam(params *cli.Context) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// BoolParam is used to check the presence of a bool flag
|
// BoolParam is used to check the presence of a bool flag
|
||||||
func boolParam(b bool) bool {
|
func boolFlag(b bool) bool {
|
||||||
if b {
|
if b {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -49,29 +86,6 @@ func WorkingDir() string {
|
||||||
return filepath.Base(dir)
|
return filepath.Base(dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
// New method puts the cli params in the struct
|
|
||||||
func New(params *cli.Context) *Config {
|
|
||||||
return &Config{
|
|
||||||
file: AppFile,
|
|
||||||
Version: AppVersion,
|
|
||||||
Projects: []Project{
|
|
||||||
{
|
|
||||||
Name: nameParam(params),
|
|
||||||
Path: filepath.Clean(params.String("path")),
|
|
||||||
Build: params.Bool("build"),
|
|
||||||
Bin: boolParam(params.Bool("no-bin")),
|
|
||||||
Run: boolParam(params.Bool("no-run")),
|
|
||||||
Fmt: boolParam(params.Bool("no-fmt")),
|
|
||||||
Watcher: Watcher{
|
|
||||||
Paths: watcherPaths,
|
|
||||||
Ignore: watcherIgnores,
|
|
||||||
Exts: watcherExts,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Duplicates check projects with same name or same combinations of main/path
|
// Duplicates check projects with same name or same combinations of main/path
|
||||||
func Duplicates(value Project, arr []Project) (error, Project) {
|
func Duplicates(value Project, arr []Project) (error, Project) {
|
||||||
for _, val := range arr {
|
for _, val := range arr {
|
||||||
|
@ -127,12 +141,13 @@ func (h *Config) Add(params *cli.Context) error {
|
||||||
err := h.Read()
|
err := h.Read()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
new := Project{
|
new := Project{
|
||||||
Name: nameParam(params),
|
Name: nameFlag(params),
|
||||||
Path: filepath.Clean(params.String("path")),
|
Path: filepath.Clean(params.String("path")),
|
||||||
Build: params.Bool("build"),
|
Build: params.Bool("build"),
|
||||||
Bin: boolParam(params.Bool("no-bin")),
|
Bin: boolFlag(params.Bool("no-bin")),
|
||||||
Run: boolParam(params.Bool("no-run")),
|
Run: boolFlag(params.Bool("no-run")),
|
||||||
Fmt: boolParam(params.Bool("no-fmt")),
|
Fmt: boolFlag(params.Bool("no-fmt")),
|
||||||
|
Params: argsParam(params),
|
||||||
Watcher: Watcher{
|
Watcher: Watcher{
|
||||||
Paths: watcherPaths,
|
Paths: watcherPaths,
|
||||||
Exts: watcherExts,
|
Exts: watcherExts,
|
||||||
|
|
|
@ -16,14 +16,14 @@ import (
|
||||||
type Project struct {
|
type Project struct {
|
||||||
reload time.Time
|
reload time.Time
|
||||||
base string
|
base string
|
||||||
Name string `yaml:"app_name,omitempty"`
|
Name string `yaml:"app_name,omitempty"`
|
||||||
Path string `yaml:"app_path,omitempty"`
|
Path string `yaml:"app_path,omitempty"`
|
||||||
Run bool `yaml:"app_run,omitempty"`
|
Run bool `yaml:"app_run,omitempty"`
|
||||||
Bin bool `yaml:"app_bin,omitempty"`
|
Bin bool `yaml:"app_bin,omitempty"`
|
||||||
Build bool `yaml:"app_build,omitempty"`
|
Build bool `yaml:"app_build,omitempty"`
|
||||||
Fmt bool `yaml:"app_fmt,omitempty"`
|
Fmt bool `yaml:"app_fmt,omitempty"`
|
||||||
Params []string `yaml:"app_params,omitempty"`
|
Params []string `yaml:"app_params,omitempty"`
|
||||||
Watcher Watcher `yaml:"app_watcher,omitempty"`
|
Watcher Watcher `yaml:"app_watcher,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GoRun is an implementation of the bin execution
|
// GoRun is an implementation of the bin execution
|
||||||
|
@ -33,7 +33,7 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
|
||||||
var build *exec.Cmd
|
var build *exec.Cmd
|
||||||
if len(p.Params) != 0 {
|
if len(p.Params) != 0 {
|
||||||
build = exec.Command(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.Path)), p.Params...)
|
build = exec.Command(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.Path)), p.Params...)
|
||||||
} else{
|
} else {
|
||||||
build = exec.Command(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.Path)))
|
build = exec.Command(filepath.Join(os.Getenv("GOBIN"), filepath.Base(p.Path)))
|
||||||
}
|
}
|
||||||
build.Dir = p.base
|
build.Dir = p.base
|
||||||
|
|
Loading…
Reference in New Issue