methods log/print removed
This commit is contained in:
parent
c74415dd80
commit
7bf980913a
3
main.go
3
main.go
@ -4,6 +4,7 @@ import (
|
||||
r "github.com/tockins/realize/realize"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
"os"
|
||||
"log"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -12,7 +13,7 @@ func main() {
|
||||
|
||||
handle := func(err error) error {
|
||||
if err != nil {
|
||||
r.Fail(err.Error())
|
||||
log.Println(r.Red(err.Error()))
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
|
@ -3,7 +3,6 @@ package realize
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fatih/color"
|
||||
"log"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@ -17,11 +16,13 @@ const (
|
||||
)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
var green = color.New(color.FgGreen, color.Bold).SprintFunc()
|
||||
var greenl = color.New(color.FgHiGreen).SprintFunc()
|
||||
var red = color.New(color.FgRed, color.Bold).SprintFunc()
|
||||
var blue = color.New(color.FgBlue, color.Bold).SprintFunc()
|
||||
var bluel = color.New(color.FgBlue).SprintFunc()
|
||||
var Green = color.New(color.FgGreen, color.Bold).SprintFunc()
|
||||
var Greenl = color.New(color.FgGreen).SprintFunc()
|
||||
var Red = color.New(color.FgRed, color.Bold).SprintFunc()
|
||||
var Redl = color.New(color.FgRed).SprintFunc()
|
||||
var Blue = color.New(color.FgBlue, color.Bold).SprintFunc()
|
||||
var Bluel = color.New(color.FgBlue).SprintFunc()
|
||||
var Magenta = color.New(color.FgMagenta).SprintFunc()
|
||||
|
||||
var watcherIgnores = []string{"vendor", "bin"}
|
||||
var watcherExts = []string{".go"}
|
||||
@ -43,43 +44,8 @@ func Init() *App {
|
||||
}
|
||||
}
|
||||
|
||||
// Fail is a red message, generally used for errors
|
||||
func Fail(msg ...interface{}) {
|
||||
color.Set(color.FgRed, color.Bold)
|
||||
fmt.Println(msg...)
|
||||
color.Unset()
|
||||
}
|
||||
|
||||
// Success is a green message, generally used for feedback
|
||||
func Success(msg ...interface{}) {
|
||||
color.Set(color.FgGreen, color.Bold)
|
||||
fmt.Println(msg...)
|
||||
color.Unset()
|
||||
}
|
||||
|
||||
// LogSuccess is a green log message, generally used for feedback
|
||||
func LogSuccess(msg ...interface{}) {
|
||||
color.Set(color.FgGreen, color.Bold)
|
||||
log.Println(msg...)
|
||||
color.Unset()
|
||||
}
|
||||
|
||||
// LogFail is a red log message, generally used for errors
|
||||
func LogFail(msg ...interface{}) {
|
||||
color.Set(color.FgRed, color.Bold)
|
||||
log.Println(msg...)
|
||||
color.Unset()
|
||||
}
|
||||
|
||||
// LogWatch is a blue log message used only for watcher outputs
|
||||
func LogWatch(msg ...interface{}) {
|
||||
color.Set(color.FgBlue, color.Bold)
|
||||
log.Println(msg...)
|
||||
color.Unset()
|
||||
}
|
||||
|
||||
// Information print realize name and description
|
||||
func (app *App) Information() {
|
||||
fmt.Println(blue(app.Name) + " - " + blue(app.Version))
|
||||
fmt.Println(bluel(app.Description) + "\n")
|
||||
fmt.Println(Blue(app.Name) + " - " + Blue(app.Version))
|
||||
fmt.Println(Bluel(app.Description) + "\n")
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ func New(params *cli.Context) *Config {
|
||||
func Duplicates(value Project, arr []Project) bool {
|
||||
for _, val := range arr {
|
||||
if value.Path == val.Path || value.Name == val.Name {
|
||||
Fail("There is a duplicate of '"+val.Name+"'. Check your config file!")
|
||||
fmt.Println(Red("There is a duplicate of '"+val.Name+"'. Check your config file!"))
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -92,7 +92,7 @@ func (h *Config) Create(params *cli.Context) error {
|
||||
if err != nil {
|
||||
os.Remove(h.file)
|
||||
} else {
|
||||
Success("The config file was successfully created")
|
||||
fmt.Println(Green("The config file was successfully created"))
|
||||
}
|
||||
return err
|
||||
}
|
||||
@ -121,7 +121,7 @@ func (h *Config) Add(params *cli.Context) error {
|
||||
h.Projects = append(h.Projects, new)
|
||||
err = h.Write()
|
||||
if err == nil {
|
||||
Success("Your project was successfully added")
|
||||
fmt.Println(Green("Your project was successfully added"))
|
||||
}
|
||||
}
|
||||
return err
|
||||
@ -136,7 +136,7 @@ func (h *Config) Remove(params *cli.Context) error {
|
||||
h.Projects = append(h.Projects[:key], h.Projects[key+1:]...)
|
||||
err = h.Write()
|
||||
if err == nil {
|
||||
Success("Your project was successfully removed")
|
||||
fmt.Println(Green("Your project was successfully removed"))
|
||||
}
|
||||
return err
|
||||
}
|
||||
@ -151,18 +151,18 @@ func (h *Config) List() error {
|
||||
err := h.Read()
|
||||
if err == nil {
|
||||
for _, val := range h.Projects {
|
||||
fmt.Println(green("|"), green(val.Name))
|
||||
fmt.Println(greenl("|"), "\t", green("Base Path:"), red(val.Path))
|
||||
fmt.Println(greenl("|"), "\t", green("Run:"), red(val.Run))
|
||||
fmt.Println(greenl("|"), "\t", green("Build:"), red(val.Build))
|
||||
fmt.Println(greenl("|"), "\t", green("Install:"), red(val.Bin))
|
||||
fmt.Println(greenl("|"), "\t", green("Watcher:"))
|
||||
fmt.Println(greenl("|"), "\t\t", green("After:"), red(val.Watcher.After))
|
||||
fmt.Println(greenl("|"), "\t\t", green("Before:"), red(val.Watcher.Before))
|
||||
fmt.Println(greenl("|"), "\t\t", green("Extensions:"), red(val.Watcher.Exts))
|
||||
fmt.Println(greenl("|"), "\t\t", green("Paths:"), red(val.Watcher.Paths))
|
||||
fmt.Println(greenl("|"), "\t\t", green("Paths ignored:"), red(val.Watcher.Ignore))
|
||||
fmt.Println(greenl("|"), "\t\t", green("Watch preview:"), red(val.Watcher.Preview))
|
||||
fmt.Println(Green("|"), Green(val.Name))
|
||||
fmt.Println(Magenta("|"), "\t", Green("Base Path"), ":", Magenta(val.Path))
|
||||
fmt.Println(Magenta("|"), "\t", Green("Run"), ":", Magenta(val.Run))
|
||||
fmt.Println(Magenta("|"), "\t", Green("Build"),":", Magenta(val.Build))
|
||||
fmt.Println(Magenta("|"), "\t", Green("Install"), ":", Magenta(val.Bin))
|
||||
fmt.Println(Magenta("|"), "\t", Green("Watcher"),":")
|
||||
fmt.Println(Magenta("|"), "\t\t", Green("After"), ":", Magenta(val.Watcher.After))
|
||||
fmt.Println(Magenta("|"), "\t\t", Green("Before"), ":", Magenta(val.Watcher.Before))
|
||||
fmt.Println(Magenta("|"), "\t\t", Green("Extensions"), ":", Magenta(val.Watcher.Exts))
|
||||
fmt.Println(Magenta("|"), "\t\t", Green("Paths"), ":", Magenta(val.Watcher.Paths))
|
||||
fmt.Println(Magenta("|"), "\t\t", Green("Paths ignored"), ":", Magenta(val.Watcher.Ignore))
|
||||
fmt.Println(Magenta("|"), "\t\t", Green("Watch preview"), ":", Magenta(val.Watcher.Preview))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -42,17 +42,17 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
|
||||
if err := build.Process.Kill(); err != nil {
|
||||
log.Fatal("failed to stop: ", err)
|
||||
}
|
||||
LogFail(p.Name + ": Stopped")
|
||||
log.Println(Redl(p.Name),":", Red("Stopped"))
|
||||
wr.Done()
|
||||
}()
|
||||
|
||||
stdout, err := build.StdoutPipe()
|
||||
if err != nil {
|
||||
Fail(err.Error())
|
||||
log.Println(Red(err.Error()))
|
||||
return err
|
||||
}
|
||||
if err := build.Start(); err != nil {
|
||||
Fail(err.Error())
|
||||
log.Println(Red(err.Error()))
|
||||
return err
|
||||
}
|
||||
close(runner)
|
||||
@ -62,7 +62,7 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
|
||||
for in.Scan() {
|
||||
select {
|
||||
default:
|
||||
log.Println(bluel(p.Name+" Out:"), bluel(in.Text()))
|
||||
log.Println(Bluel(p.Name+" Out:"), Bluel(in.Text()))
|
||||
}
|
||||
}
|
||||
close(stop)
|
||||
@ -81,7 +81,7 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
|
||||
// GoBuild an implementation of the "go build"
|
||||
func (p *Project) GoBuild() error {
|
||||
var out bytes.Buffer
|
||||
|
||||
|
||||
build := exec.Command("go", "build")
|
||||
build.Dir = p.base
|
||||
build.Stdout = &out
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"log"
|
||||
)
|
||||
|
||||
// The Watcher struct defines the livereload's logic
|
||||
@ -44,12 +45,12 @@ func (p *Project) Watching() {
|
||||
var watcher *fsnotify.Watcher
|
||||
watcher, err := fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
Fail(p.Name + ": \t" + err.Error())
|
||||
log.Println(Redl(p.Name),": \t", Red(err.Error()))
|
||||
}
|
||||
channel := make(chan bool, 1)
|
||||
base, err := os.Getwd()
|
||||
if err != nil {
|
||||
Fail(p.Name + ": \t" + err.Error())
|
||||
log.Println(Redl(p.Name),": \t", Red(err.Error()))
|
||||
}
|
||||
|
||||
walk := func(path string, info os.FileInfo, err error) error {
|
||||
@ -86,14 +87,14 @@ func (p *Project) Watching() {
|
||||
base = p.base + dir
|
||||
if _, err := os.Stat(base); err == nil {
|
||||
if err := filepath.Walk(base, walk); err != nil {
|
||||
Fail(err.Error())
|
||||
log.Println(Red(err.Error()))
|
||||
}
|
||||
} else {
|
||||
Fail(p.Name + ": \t" + base + " path doesn't exist")
|
||||
fmt.Println(Redl(p.Name), ":\t", Red(base + " path doesn't exist"))
|
||||
}
|
||||
}
|
||||
routines()
|
||||
fmt.Println(red("Watching: '" + p.Name + "'\n"))
|
||||
fmt.Println(Red("Watching: '" + p.Name + "'\n"))
|
||||
p.reload = time.Now().Truncate(time.Second)
|
||||
for {
|
||||
select {
|
||||
@ -105,7 +106,7 @@ func (p *Project) Watching() {
|
||||
if _, err := os.Stat(event.Name); err == nil {
|
||||
i := strings.Index(event.Name, filepath.Ext(event.Name))
|
||||
if event.Name[:i] != "" {
|
||||
LogWatch(p.Name+":", "File changed ->", event.Name[:i])
|
||||
log.Println(Magenta(p.Name),":", Magenta("File changed"), "->", Blue(event.Name[:i]))
|
||||
|
||||
// stop and run again
|
||||
close(channel)
|
||||
@ -117,7 +118,7 @@ func (p *Project) Watching() {
|
||||
}
|
||||
}
|
||||
case err := <-watcher.Errors:
|
||||
Fail(err.Error())
|
||||
log.Println(Red(err.Error()))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -125,21 +126,22 @@ func (p *Project) Watching() {
|
||||
// Install call an implementation of the "go install"
|
||||
func (p *Project) install(channel chan bool,wr *sync.WaitGroup) {
|
||||
if p.Bin {
|
||||
LogSuccess(p.Name + ": Installing..")
|
||||
log.Println(Greenl(p.Name), ":", Greenl("Installing.."))
|
||||
start := time.Now()
|
||||
if err := p.GoInstall(); err != nil {
|
||||
Fail(p.Name + ": "+err.Error())
|
||||
log.Println(Redl(p.Name),":",Red(err.Error()))
|
||||
wr.Done()
|
||||
} else {
|
||||
LogSuccess(p.Name+":", "Installed after", time.Since(start))
|
||||
log.Println(Greenl(p.Name),":", Green("Installed")+ " after", Magenta(time.Since(start)))
|
||||
if p.Run {
|
||||
runner := make(chan bool, 1)
|
||||
LogSuccess(p.Name + ": Running..")
|
||||
log.Println(Greenl(p.Name), ":", Greenl("Running.."))
|
||||
start = time.Now()
|
||||
go p.GoRun(channel, runner, wr)
|
||||
for {
|
||||
select {
|
||||
case <-runner:
|
||||
LogSuccess(p.Name + ": Has been run")
|
||||
log.Println(Greenl(p.Name), ":", Green("Has been run") + " after", Magenta(time.Since(start)))
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -152,12 +154,12 @@ func (p *Project) install(channel chan bool,wr *sync.WaitGroup) {
|
||||
// Build call an implementation of the "go build"
|
||||
func (p *Project) build() {
|
||||
if p.Build {
|
||||
LogSuccess(p.Name + ": Building..")
|
||||
log.Println(Greenl(p.Name), ":", Greenl("Building.."))
|
||||
start := time.Now()
|
||||
if err := p.GoBuild(); err != nil {
|
||||
Fail(p.Name + ": "+err.Error())
|
||||
log.Println(Redl(p.Name), ":", Red(err.Error()))
|
||||
} else {
|
||||
LogSuccess(p.Name+":", "Builded after", time.Since(start))
|
||||
log.Println(Greenl(p.Name),":", Green("Builded")+ " after", Magenta(time.Since(start)))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user