interface removed, utils folder
This commit is contained in:
parent
e0e72325a4
commit
943dc81456
120
app/main.go
120
app/main.go
@ -2,7 +2,8 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
c "github.com/tockins/realize/cli"
|
w "github.com/tockins/realize/cli"
|
||||||
|
c "github.com/tockins/realize/config"
|
||||||
s "github.com/tockins/realize/server"
|
s "github.com/tockins/realize/server"
|
||||||
"gopkg.in/urfave/cli.v2"
|
"gopkg.in/urfave/cli.v2"
|
||||||
"log"
|
"log"
|
||||||
@ -15,36 +16,19 @@ const (
|
|||||||
Version = "1.1"
|
Version = "1.1"
|
||||||
Description = "A Go build system with file watchers, output streams and live reload. Run, build and watch file changes with custom paths"
|
Description = "A Go build system with file watchers, output streams and live reload. Run, build and watch file changes with custom paths"
|
||||||
Limit = 10000
|
Limit = 10000
|
||||||
Config = "r.config.yaml"
|
Config = "R.config.yaml"
|
||||||
Output = "r.output.log"
|
Output = "R.output.log"
|
||||||
Host = "Web server listening on localhost:5000"
|
Host = "Web server listening on localhost:5000"
|
||||||
)
|
)
|
||||||
|
|
||||||
var r realize
|
var R Realize
|
||||||
var R Realizer
|
|
||||||
|
|
||||||
// Realizer interface for wrap the cli, app and server functions
|
|
||||||
type Realizer interface {
|
|
||||||
Wdir() string
|
|
||||||
Red(string) string
|
|
||||||
Blue(string) string
|
|
||||||
BlueS(string) string
|
|
||||||
Handle(error) error
|
|
||||||
Serve(*cli.Context)
|
|
||||||
Before(*cli.Context) error
|
|
||||||
Fast(*cli.Context) error
|
|
||||||
Run(*cli.Context) error
|
|
||||||
Add(*cli.Context) error
|
|
||||||
Remove(*cli.Context) error
|
|
||||||
List(*cli.Context) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// Realize struct contains the general app informations
|
// Realize struct contains the general app informations
|
||||||
type realize struct {
|
type Realize struct {
|
||||||
Name, Description, Author, Email, Host string
|
Name, Description, Author, Email, Host string
|
||||||
Version string
|
Version string
|
||||||
Limit uint64
|
Limit uint64
|
||||||
Blueprint c.Blueprint
|
Blueprint w.Blueprint
|
||||||
Server s.Server
|
Server s.Server
|
||||||
Files map[string]string
|
Files map[string]string
|
||||||
Sync chan string
|
Sync chan string
|
||||||
@ -52,7 +36,7 @@ type realize struct {
|
|||||||
|
|
||||||
// Application initialization
|
// Application initialization
|
||||||
func init() {
|
func init() {
|
||||||
r = realize{
|
R = Realize{
|
||||||
Name: Name,
|
Name: Name,
|
||||||
Version: Version,
|
Version: Version,
|
||||||
Description: Description,
|
Description: Description,
|
||||||
@ -64,91 +48,89 @@ func init() {
|
|||||||
},
|
},
|
||||||
Sync: make(chan string),
|
Sync: make(chan string),
|
||||||
}
|
}
|
||||||
r.Blueprint = c.Blueprint{
|
R.Blueprint = w.Blueprint{
|
||||||
Files: r.Files,
|
Files: R.Files,
|
||||||
Sync: r.Sync,
|
Sync: R.Sync,
|
||||||
}
|
}
|
||||||
r.Server = s.Server{
|
R.Server = s.Server{
|
||||||
Blueprint: &r.Blueprint,
|
Blueprint: &R.Blueprint,
|
||||||
Files: r.Files,
|
Files: R.Files,
|
||||||
Sync: r.Sync,
|
Sync: R.Sync,
|
||||||
}
|
}
|
||||||
r.Increase()
|
R.limit()
|
||||||
R = &r
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flimit defines the max number of watched files
|
// Flimit defines the max number of watched files
|
||||||
func (r *realize) Increase() {
|
func (r *Realize) limit() {
|
||||||
// increases the files limit
|
|
||||||
var rLimit syscall.Rlimit
|
var rLimit syscall.Rlimit
|
||||||
rLimit.Max = r.Limit
|
rLimit.Max = R.Limit
|
||||||
rLimit.Cur = r.Limit
|
rLimit.Cur = R.Limit
|
||||||
err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(c.Red("Error Setting Rlimit "), err)
|
log.Fatal(w.Red("Error Setting Rlimit "), err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *realize) Red(s string) string {
|
func (r *Realize) Red(s string) string {
|
||||||
return c.Red(s)
|
return w.Red(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *realize) Blue(s string) string {
|
func (r *Realize) Blue(s string) string {
|
||||||
return c.Blue(s)
|
return w.Blue(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *realize) BlueS(s string) string {
|
func (r *Realize) BlueS(s string) string {
|
||||||
return c.BlueS(s)
|
return w.BlueS(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *realize) Wdir() string {
|
func (r *Realize) Dir() string {
|
||||||
return c.WorkingDir()
|
return c.Wdir()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *realize) Serve(p *cli.Context) {
|
func (r *Realize) Serve(p *cli.Context) {
|
||||||
if !p.Bool("no-server") {
|
if !p.Bool("no-server") {
|
||||||
fmt.Println(r.Red(r.Host) + "\n")
|
fmt.Println(R.Red(R.Host) + "\n")
|
||||||
r.Server.Open = p.Bool("open")
|
R.Server.Open = p.Bool("open")
|
||||||
r.Server.Start()
|
R.Server.Start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *realize) Run(p *cli.Context) error {
|
func (r *Realize) Run(p *cli.Context) error {
|
||||||
r.Serve(p)
|
R.Serve(p)
|
||||||
return r.Blueprint.Run()
|
return R.Blueprint.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *realize) Fast(p *cli.Context) error {
|
func (r *Realize) Fast(p *cli.Context) error {
|
||||||
r.Blueprint.Add(p)
|
R.Blueprint.Add(p)
|
||||||
r.Serve(p)
|
R.Serve(p)
|
||||||
return r.Blueprint.Fast(p)
|
return R.Blueprint.Fast(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *realize) Add(p *cli.Context) error {
|
func (r *Realize) Add(p *cli.Context) error {
|
||||||
return r.Blueprint.Insert(p)
|
return R.Blueprint.Insert(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *realize) Remove(p *cli.Context) error {
|
func (r *Realize) Remove(p *cli.Context) error {
|
||||||
return r.Blueprint.Insert(p)
|
return R.Blueprint.Insert(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *realize) List(p *cli.Context) error {
|
func (r *Realize) List(p *cli.Context) error {
|
||||||
return r.Blueprint.List()
|
return R.Blueprint.List()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *realize) Before(p *cli.Context) error {
|
func (r *Realize) Before(p *cli.Context) error {
|
||||||
fmt.Println(r.Blue(r.Name) + " - " + r.Blue(r.Version))
|
fmt.Println(R.Blue(R.Name) + " - " + R.Blue(R.Version))
|
||||||
fmt.Println(r.BlueS(r.Description) + "\n")
|
fmt.Println(R.BlueS(R.Description) + "\n")
|
||||||
gopath := os.Getenv("GOPATH")
|
gopath := os.Getenv("GOPATH")
|
||||||
if gopath == "" {
|
if gopath == "" {
|
||||||
log.Fatal(r.Red("$GOPATH isn't set up properly"))
|
log.Fatal(R.Red("$GOPATH isn't set up properly"))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *realize) Handle(err error) error {
|
func (r *Realize) Handle(err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(r.Red(err.Error()))
|
fmt.Println(R.Red(err.Error()))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
22
config/utils.go
Normal file
22
config/utils.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Utils struct{}
|
||||||
|
|
||||||
|
func Wdir() string {
|
||||||
|
dir, err := os.Getwd()
|
||||||
|
Validate(err)
|
||||||
|
return filepath.Base(dir)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Validate(err error) error {
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
@ -6,10 +6,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
var app a.Realizer
|
var app a.Realize
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app = a.R
|
|
||||||
c := &cli.App{
|
c := &cli.App{
|
||||||
Name: a.Name,
|
Name: a.Name,
|
||||||
Version: a.Version,
|
Version: a.Version,
|
||||||
@ -66,7 +65,7 @@ func main() {
|
|||||||
Aliases: []string{"a"},
|
Aliases: []string{"a"},
|
||||||
Usage: "Add another project",
|
Usage: "Add another project",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.StringFlag{Name: "name", Aliases: []string{"n"}, Value: app.Wdir(), Usage: "Project name"},
|
&cli.StringFlag{Name: "name", Aliases: []string{"n"}, Value: app.Dir(), Usage: "Project name"},
|
||||||
&cli.StringFlag{Name: "path", Aliases: []string{"b"}, Value: "/", Usage: "Project base path"},
|
&cli.StringFlag{Name: "path", Aliases: []string{"b"}, Value: "/", Usage: "Project base path"},
|
||||||
&cli.BoolFlag{Name: "build", Value: false, Usage: "Enable the build"},
|
&cli.BoolFlag{Name: "build", Value: false, Usage: "Enable the build"},
|
||||||
&cli.BoolFlag{Name: "no-run", Usage: "Disables the run"},
|
&cli.BoolFlag{Name: "no-run", Usage: "Disables the run"},
|
||||||
|
Loading…
Reference in New Issue
Block a user