wdir moved to config
This commit is contained in:
parent
943dc81456
commit
cf1461b5f1
|
@ -25,6 +25,7 @@ var R Realize
|
||||||
|
|
||||||
// Realize struct contains the general app informations
|
// Realize struct contains the general app informations
|
||||||
type Realize struct {
|
type Realize struct {
|
||||||
|
c.Utils
|
||||||
Name, Description, Author, Email, Host string
|
Name, Description, Author, Email, Host string
|
||||||
Version string
|
Version string
|
||||||
Limit uint64
|
Limit uint64
|
||||||
|
@ -49,6 +50,7 @@ func init() {
|
||||||
Sync: make(chan string),
|
Sync: make(chan string),
|
||||||
}
|
}
|
||||||
R.Blueprint = w.Blueprint{
|
R.Blueprint = w.Blueprint{
|
||||||
|
Utils: R.Utils,
|
||||||
Files: R.Files,
|
Files: R.Files,
|
||||||
Sync: R.Sync,
|
Sync: R.Sync,
|
||||||
}
|
}
|
||||||
|
@ -84,7 +86,7 @@ func (r *Realize) BlueS(s string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Realize) Dir() string {
|
func (r *Realize) Dir() string {
|
||||||
return c.Wdir()
|
return r.Wdir()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Realize) Serve(p *cli.Context) {
|
func (r *Realize) Serve(p *cli.Context) {
|
||||||
|
|
|
@ -55,7 +55,6 @@ func (h *Blueprint) Fast(params *cli.Context) error {
|
||||||
// Add a new project
|
// Add a new project
|
||||||
func (h *Blueprint) Add(params *cli.Context) error {
|
func (h *Blueprint) Add(params *cli.Context) error {
|
||||||
p := Project{
|
p := Project{
|
||||||
Name: nameFlag(params),
|
|
||||||
Path: filepath.Clean(params.String("path")),
|
Path: filepath.Clean(params.String("path")),
|
||||||
Build: params.Bool("build"),
|
Build: params.Bool("build"),
|
||||||
Bin: boolFlag(params.Bool("no-bin")),
|
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 {
|
if _, err := duplicates(p, h.Projects); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
|
c "github.com/tockins/realize/config"
|
||||||
"log"
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -24,6 +25,7 @@ type logWriter struct{}
|
||||||
|
|
||||||
// Projects struct contains a projects list
|
// Projects struct contains a projects list
|
||||||
type Blueprint struct {
|
type Blueprint struct {
|
||||||
|
c.Utils
|
||||||
Projects []Project `yaml:"projects,omitempty"`
|
Projects []Project `yaml:"projects,omitempty"`
|
||||||
Files map[string]string `yaml:"-"`
|
Files map[string]string `yaml:"-"`
|
||||||
Sync chan string `yaml:"-"`
|
Sync chan string `yaml:"-"`
|
||||||
|
@ -31,6 +33,7 @@ type Blueprint struct {
|
||||||
|
|
||||||
// Project defines the informations of a single project
|
// Project defines the informations of a single project
|
||||||
type Project struct {
|
type Project struct {
|
||||||
|
c.Utils
|
||||||
LastChangedOn time.Time `yaml:"-"`
|
LastChangedOn time.Time `yaml:"-"`
|
||||||
base string
|
base string
|
||||||
Name string `yaml:"app_name,omitempty"`
|
Name string `yaml:"app_name,omitempty"`
|
||||||
|
|
13
cli/utils.go
13
cli/utils.go
|
@ -12,15 +12,6 @@ import (
|
||||||
"time"
|
"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
|
// Read a file given a name and return its byte stream
|
||||||
func read(file string) ([]byte, error) {
|
func read(file string) ([]byte, error) {
|
||||||
_, err := os.Stat(file)
|
_, 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
|
// 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
|
var name string
|
||||||
if params.String("name") == "" && params.String("path") == "" {
|
if params.String("name") == "" && params.String("path") == "" {
|
||||||
return WorkingDir()
|
return p.Wdir()
|
||||||
} else if params.String("path") != "/" {
|
} else if params.String("path") != "/" {
|
||||||
name = filepath.Base(params.String("path"))
|
name = filepath.Base(params.String("path"))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -223,7 +223,7 @@ func (p *Project) walks(watcher *fsnotify.Watcher) error {
|
||||||
|
|
||||||
if p.Path == "." || p.Path == "/" {
|
if p.Path == "." || p.Path == "/" {
|
||||||
p.base = wd
|
p.base = wd
|
||||||
p.Path = WorkingDir()
|
p.Path = p.Wdir()
|
||||||
} else if filepath.IsAbs(p.Path) {
|
} else if filepath.IsAbs(p.Path) {
|
||||||
p.base = p.Path
|
p.base = p.Path
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -8,13 +8,13 @@ import (
|
||||||
|
|
||||||
type Utils struct{}
|
type Utils struct{}
|
||||||
|
|
||||||
func Wdir() string {
|
func (u *Utils) Wdir() string {
|
||||||
dir, err := os.Getwd()
|
dir, err := os.Getwd()
|
||||||
Validate(err)
|
u.Validate(err)
|
||||||
return filepath.Base(dir)
|
return filepath.Base(dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Validate(err error) error {
|
func (u *Utils) Validate(err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue