wdir moved to config

This commit is contained in:
alessio 2016-10-21 16:14:39 +02:00
parent 943dc81456
commit cf1461b5f1
6 changed files with 13 additions and 17 deletions

View File

@ -25,6 +25,7 @@ var R Realize
// Realize struct contains the general app informations
type Realize struct {
c.Utils
Name, Description, Author, Email, Host string
Version string
Limit uint64
@ -49,6 +50,7 @@ func init() {
Sync: make(chan string),
}
R.Blueprint = w.Blueprint{
Utils: R.Utils,
Files: R.Files,
Sync: R.Sync,
}
@ -84,7 +86,7 @@ func (r *Realize) BlueS(s string) string {
}
func (r *Realize) Dir() string {
return c.Wdir()
return r.Wdir()
}
func (r *Realize) Serve(p *cli.Context) {

View File

@ -55,7 +55,6 @@ func (h *Blueprint) Fast(params *cli.Context) error {
// Add a new project
func (h *Blueprint) Add(params *cli.Context) error {
p := Project{
Name: nameFlag(params),
Path: filepath.Clean(params.String("path")),
Build: params.Bool("build"),
Bin: boolFlag(params.Bool("no-bin")),
@ -73,6 +72,7 @@ func (h *Blueprint) Add(params *cli.Context) error {
},
},
}
p.Name = p.nameFlag(params)
if _, err := duplicates(p, h.Projects); err != nil {
return err
}

View File

@ -2,6 +2,7 @@ package cli
import (
"github.com/fatih/color"
c "github.com/tockins/realize/config"
"log"
"sync"
"time"
@ -24,6 +25,7 @@ type logWriter struct{}
// Projects struct contains a projects list
type Blueprint struct {
c.Utils
Projects []Project `yaml:"projects,omitempty"`
Files map[string]string `yaml:"-"`
Sync chan string `yaml:"-"`
@ -31,6 +33,7 @@ type Blueprint struct {
// Project defines the informations of a single project
type Project struct {
c.Utils
LastChangedOn time.Time `yaml:"-"`
base string
Name string `yaml:"app_name,omitempty"`

View File

@ -12,15 +12,6 @@ import (
"time"
)
// WorkingDir returns the name last element of the working directory path
func WorkingDir() string {
dir, err := os.Getwd()
if err != nil {
log.Fatal(Red(err))
}
return filepath.Base(dir)
}
// Read a file given a name and return its byte stream
func read(file string) ([]byte, error) {
_, err := os.Stat(file)
@ -67,10 +58,10 @@ func argsParam(params *cli.Context) []string {
}
// NameParam check the project name presence. If empty takes the working directory name
func nameFlag(params *cli.Context) string {
func (p *Project) nameFlag(params *cli.Context) string {
var name string
if params.String("name") == "" && params.String("path") == "" {
return WorkingDir()
return p.Wdir()
} else if params.String("path") != "/" {
name = filepath.Base(params.String("path"))
} else {

View File

@ -223,7 +223,7 @@ func (p *Project) walks(watcher *fsnotify.Watcher) error {
if p.Path == "." || p.Path == "/" {
p.base = wd
p.Path = WorkingDir()
p.Path = p.Wdir()
} else if filepath.IsAbs(p.Path) {
p.base = p.Path
} else {

View File

@ -8,13 +8,13 @@ import (
type Utils struct{}
func Wdir() string {
func (u *Utils) Wdir() string {
dir, err := os.Getwd()
Validate(err)
u.Validate(err)
return filepath.Base(dir)
}
func Validate(err error) error {
func (u *Utils) Validate(err error) error {
if err != nil {
log.Fatal(err)
}