cli run/build/install more simples

This commit is contained in:
alessio 2016-08-21 09:37:56 +02:00
parent 8b50a6d8e0
commit e222280345
2 changed files with 17 additions and 9 deletions

View File

@ -87,8 +87,8 @@ func main() {
&cli.StringFlag{Name: "name", Aliases: []string{"n"}, Usage: "Project name \t"}, &cli.StringFlag{Name: "name", Aliases: []string{"n"}, Usage: "Project name \t"},
&cli.StringFlag{Name: "base", Aliases: []string{"b"}, Value: wd(), Usage: "Project base path \t"}, &cli.StringFlag{Name: "base", Aliases: []string{"b"}, Value: wd(), Usage: "Project base path \t"},
&cli.BoolFlag{Name: "build", Value: false}, &cli.BoolFlag{Name: "build", Value: false},
&cli.BoolFlag{Name: "run", Value: true}, &cli.BoolFlag{Name: "run"},
&cli.BoolFlag{Name: "bin", Value: true}, &cli.BoolFlag{Name: "bin"},
}, },
Action: func(p *cli.Context) error { Action: func(p *cli.Context) error {
y := r.New(p) y := r.New(p)

View File

@ -16,7 +16,8 @@ type Config struct {
Projects []Project Projects []Project
} }
func projectName(params *cli.Context) string{ // nameParam check the project name presence. If empty takes the working directory name
func nameParam(params *cli.Context) string{
var name string var name string
if params.String("name") == "" { if params.String("name") == "" {
name = params.String("base") name = params.String("base")
@ -26,6 +27,13 @@ func projectName(params *cli.Context) string{
return name return name
} }
func boolParam(b bool) bool{
if b{
return false
}
return true
}
// New method puts the cli params in the struct // New method puts the cli params in the struct
func New(params *cli.Context) *Config { func New(params *cli.Context) *Config {
return &Config{ return &Config{
@ -33,11 +41,11 @@ func New(params *cli.Context) *Config {
Version: AppVersion, Version: AppVersion,
Projects: []Project{ Projects: []Project{
{ {
Name: projectName(params), Name: nameParam(params),
Path: params.String("base"), Path: params.String("base"),
Run: params.Bool("run"),
Build: params.Bool("build"), Build: params.Bool("build"),
Bin: params.Bool("bin"), Bin: boolParam(params.Bool("bin")),
Run: boolParam(params.Bool("run")),
Watcher: Watcher{ Watcher: Watcher{
Paths: watcherPaths, Paths: watcherPaths,
Ignore: watcherIgnores, Ignore: watcherIgnores,
@ -113,11 +121,11 @@ 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: projectName(params), Name: nameParam(params),
Path: params.String("base"), Path: params.String("base"),
Run: params.Bool("run"),
Build: params.Bool("build"), Build: params.Bool("build"),
Bin: params.Bool("bin"), Bin: boolParam(params.Bool("bin")),
Run: boolParam(params.Bool("run")),
Watcher: Watcher{ Watcher: Watcher{
Paths: watcherPaths, Paths: watcherPaths,
Exts: watcherExts, Exts: watcherExts,