colors var

This commit is contained in:
alessio 2016-07-27 13:42:25 +02:00
parent c82f0d9f14
commit 3d36e57ad9
2 changed files with 41 additions and 7 deletions

33
main.go
View File

@ -5,16 +5,22 @@ import (
"fmt" "fmt"
"gopkg.in/urfave/cli.v2" "gopkg.in/urfave/cli.v2"
"github.com/tockins/realize/realize" "github.com/tockins/realize/realize"
"github.com/fatih/color"
) )
const( const(
name = "Realize" name = "Realize"
version = "v1.0" version = "v1.0"
email = "pracchia@hastega.it" email = "pracchia@hastega.it"
description = "Run and build your applications on file changes. Watch custom paths and specific extensions. Define additional commands and multiple projects" //description = "Run and build your applications on file changes. Watch custom paths and specific extensions. Define additional commands and multiple projects"
description = "Run and build your applications on file changes."
author = "Alessio Pracchia" author = "Alessio Pracchia"
) )
var blue = color.New(color.FgBlue, color.Bold).SprintFunc()
var bluel = color.New(color.FgBlue).SprintFunc()
func main() { func main() {
handle := func(err error) error{ handle := func(err error) error{
@ -24,6 +30,11 @@ func main() {
return nil return nil
} }
header := func(){
fmt.Println(blue(name)+" - "+blue(version))
fmt.Println(bluel(description)+"\n")
}
app := &cli.App{ app := &cli.App{
Name: name, Name: name,
Version: version, Version: version,
@ -42,6 +53,10 @@ func main() {
fmt.Printf("Hello %q", p.String("run")) fmt.Printf("Hello %q", p.String("run"))
return nil return nil
}, },
Before: func(c *cli.Context) error {
header()
return nil
},
}, },
{ {
Name: "start", Name: "start",
@ -58,6 +73,10 @@ func main() {
y := realize.New(p) y := realize.New(p)
return handle(y.Create(p)) return handle(y.Create(p))
}, },
Before: func(c *cli.Context) error {
header()
return nil
},
}, },
{ {
Name: "add", Name: "add",
@ -74,6 +93,10 @@ func main() {
y := realize.New(p) y := realize.New(p)
return handle(y.Add(p)) return handle(y.Add(p))
}, },
Before: func(c *cli.Context) error {
header()
return nil
},
}, },
{ {
Name: "remove", Name: "remove",
@ -87,6 +110,10 @@ func main() {
y := realize.New(p) y := realize.New(p)
return handle(y.Remove(p)) return handle(y.Remove(p))
}, },
Before: func(c *cli.Context) error {
header()
return nil
},
}, },
{ {
Name: "list", Name: "list",
@ -97,6 +124,10 @@ func main() {
y := realize.New(p) y := realize.New(p)
return handle(y.List()) return handle(y.List())
}, },
Before: func(c *cli.Context) error {
header()
return nil
},
}, },
}, },
} }

View File

@ -12,8 +12,13 @@ import (
const( const(
file = "realize.config.yaml" file = "realize.config.yaml"
ext = "go"
path = "/"
) )
var green = color.New(color.FgGreen, color.Bold).SprintFunc()
var greenl = color.New(color.FgHiGreen).SprintFunc()
type Config struct { type Config struct {
file string `yaml:"app_file,omitempty"` file string `yaml:"app_file,omitempty"`
Version string `yaml:"version,omitempty"` Version string `yaml:"version,omitempty"`
@ -47,8 +52,8 @@ func New(params *cli.Context) *Config{
Run: params.Bool("run"), Run: params.Bool("run"),
Build: params.Bool("build"), Build: params.Bool("build"),
Watcher: Watcher{ Watcher: Watcher{
Paths: []string{"/"}, Paths: []string{ext},
Exts: []string{"go"}, Exts: []string{path},
}, },
}, },
}, },
@ -120,8 +125,8 @@ func (h *Config) Add(params *cli.Context) error{
Run: params.Bool("run"), Run: params.Bool("run"),
Build: params.Bool("build"), Build: params.Bool("build"),
Watcher: Watcher{ Watcher: Watcher{
Paths: []string{"/"}, Paths: []string{ext},
Exts: []string{"go"}, Exts: []string{path},
}, },
} }
if Duplicates(new, h.Projects) { if Duplicates(new, h.Projects) {
@ -152,8 +157,6 @@ func (h *Config) Remove(params *cli.Context) error{
// List of projects // List of projects
func (h *Config) List() error{ func (h *Config) List() error{
if err := h.Read(); err == nil { if err := h.Read(); err == nil {
green := color.New(color.FgGreen, color.Bold).SprintFunc()
greenl := color.New(color.FgHiGreen).SprintFunc()
red := color.New(color.FgRed).SprintFunc() red := color.New(color.FgRed).SprintFunc()
for _, val := range h.Projects { for _, val := range h.Projects {
fmt.Println(green("|"), green(val.Name)) fmt.Println(green("|"), green(val.Name))