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"
"gopkg.in/urfave/cli.v2"
"github.com/tockins/realize/realize"
"github.com/fatih/color"
)
const(
name = "Realize"
version = "v1.0"
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"
)
var blue = color.New(color.FgBlue, color.Bold).SprintFunc()
var bluel = color.New(color.FgBlue).SprintFunc()
func main() {
handle := func(err error) error{
@ -24,6 +30,11 @@ func main() {
return nil
}
header := func(){
fmt.Println(blue(name)+" - "+blue(version))
fmt.Println(bluel(description)+"\n")
}
app := &cli.App{
Name: name,
Version: version,
@ -42,6 +53,10 @@ func main() {
fmt.Printf("Hello %q", p.String("run"))
return nil
},
Before: func(c *cli.Context) error {
header()
return nil
},
},
{
Name: "start",
@ -58,6 +73,10 @@ func main() {
y := realize.New(p)
return handle(y.Create(p))
},
Before: func(c *cli.Context) error {
header()
return nil
},
},
{
Name: "add",
@ -74,6 +93,10 @@ func main() {
y := realize.New(p)
return handle(y.Add(p))
},
Before: func(c *cli.Context) error {
header()
return nil
},
},
{
Name: "remove",
@ -87,6 +110,10 @@ func main() {
y := realize.New(p)
return handle(y.Remove(p))
},
Before: func(c *cli.Context) error {
header()
return nil
},
},
{
Name: "list",
@ -97,6 +124,10 @@ func main() {
y := realize.New(p)
return handle(y.List())
},
Before: func(c *cli.Context) error {
header()
return nil
},
},
},
}

View File

@ -12,8 +12,13 @@ import (
const(
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 {
file string `yaml:"app_file,omitempty"`
Version string `yaml:"version,omitempty"`
@ -47,8 +52,8 @@ func New(params *cli.Context) *Config{
Run: params.Bool("run"),
Build: params.Bool("build"),
Watcher: Watcher{
Paths: []string{"/"},
Exts: []string{"go"},
Paths: []string{ext},
Exts: []string{path},
},
},
},
@ -120,8 +125,8 @@ func (h *Config) Add(params *cli.Context) error{
Run: params.Bool("run"),
Build: params.Bool("build"),
Watcher: Watcher{
Paths: []string{"/"},
Exts: []string{"go"},
Paths: []string{ext},
Exts: []string{path},
},
}
if Duplicates(new, h.Projects) {
@ -152,8 +157,6 @@ func (h *Config) Remove(params *cli.Context) error{
// List of projects
func (h *Config) List() error{
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()
for _, val := range h.Projects {
fmt.Println(green("|"), green(val.Name))