#100 name flag fixed
This commit is contained in:
parent
b3bb5c9e91
commit
227871d171
10
cmd.go
10
cmd.go
|
@ -62,8 +62,8 @@ func (r *realize) check() error {
|
|||
// Add a new project
|
||||
func (r *realize) add(p *cli.Context) error {
|
||||
project := Project{
|
||||
Name: r.Settings.name(p.String("name"), p.String("path")),
|
||||
Path: r.Settings.path(p.String("path")),
|
||||
Name: filepath.Base(filepath.Clean(p.String("path"))),
|
||||
Path: filepath.Clean(p.String("path")),
|
||||
Cmds: Cmds{
|
||||
Vet: Cmd{
|
||||
Status: p.Bool("vet"),
|
||||
|
@ -101,6 +101,7 @@ func (r *realize) add(p *cli.Context) error {
|
|||
|
||||
// Run launches the toolchain for each project
|
||||
func (r *realize) run(p *cli.Context) error {
|
||||
var match bool
|
||||
err := r.check()
|
||||
if err == nil {
|
||||
// loop projects
|
||||
|
@ -214,10 +215,13 @@ func (r *realize) run(p *cli.Context) error {
|
|||
} else {
|
||||
r.Schema[k].base = filepath.Join(wd, elm.path)
|
||||
}
|
||||
match = true
|
||||
go r.Schema[k].watch()
|
||||
}
|
||||
if !match {
|
||||
return errors.New("there is no project with the given name")
|
||||
}
|
||||
wg.Wait()
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
36
realize.go
36
realize.go
|
@ -8,6 +8,7 @@ import (
|
|||
"gopkg.in/urfave/cli.v2"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
@ -52,7 +53,7 @@ func main() {
|
|||
Aliases: []string{"r"},
|
||||
Description: "Start a toolchain on a project or a list of projects. If not exist a config file it creates a new one",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{Name: "path", Aliases: []string{"p"}, Value: "", Usage: "Project base path"},
|
||||
&cli.StringFlag{Name: "path", Aliases: []string{"p"}, Value: wdir(), Usage: "Project base path"},
|
||||
&cli.StringFlag{Name: "name", Aliases: []string{"n"}, Value: "", Usage: "Run a project by its name"},
|
||||
&cli.BoolFlag{Name: "fmt", Aliases: []string{"f"}, Value: false, Usage: "Enable go fmt"},
|
||||
&cli.BoolFlag{Name: "vet", Aliases: []string{"v"}, Value: false, Usage: "Enable go vet"},
|
||||
|
@ -68,7 +69,7 @@ func main() {
|
|||
if err := r.insert(p); err != nil {
|
||||
return err
|
||||
}
|
||||
if !p.Bool("no-config") {
|
||||
if !p.Bool("no-config") && p.String("name") == ""{
|
||||
if err := r.Settings.record(r); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -86,7 +87,7 @@ func main() {
|
|||
Aliases: []string{"a"},
|
||||
Description: "Add a project to an existing config file or create a new one",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{Name: "path", Aliases: []string{"p"}, Value: "", Usage: "Project base path"},
|
||||
&cli.StringFlag{Name: "path", Aliases: []string{"p"}, Value: wdir(), Usage: "Project base path"},
|
||||
&cli.BoolFlag{Name: "fmt", Aliases: []string{"f"}, Value: false, Usage: "Enable go fmt"},
|
||||
&cli.BoolFlag{Name: "vet", Aliases: []string{"v"}, Value: false, Usage: "Enable go vet"},
|
||||
&cli.BoolFlag{Name: "test", Aliases: []string{"t"}, Value: false, Usage: "Enable go test"},
|
||||
|
@ -102,7 +103,7 @@ func main() {
|
|||
if err := r.Settings.record(r); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintln(output, prefix(green.bold("Your project was successfully added")))
|
||||
log.Println(prefix(green.bold("Your project was successfully added")))
|
||||
return nil
|
||||
},
|
||||
Before: before,
|
||||
|
@ -116,7 +117,7 @@ func main() {
|
|||
interact.Run(&interact.Interact{
|
||||
Before: func(context interact.Context) error {
|
||||
context.SetErr(red.bold("INVALID INPUT"))
|
||||
context.SetPrfx(color.Output, yellow.bold("[")+"REALIZE"+yellow.bold("]"))
|
||||
context.SetPrfx(color.Output, yellow.regular("[") + time.Now().Format("15:04:05") + yellow.regular("]") + yellow.bold("[")+"REALIZE"+yellow.bold("]"))
|
||||
return nil
|
||||
},
|
||||
Questions: []*interact.Question{
|
||||
|
@ -361,7 +362,7 @@ func main() {
|
|||
},
|
||||
{
|
||||
Before: func(d interact.Context) error {
|
||||
dir, _ := os.Getwd()
|
||||
dir := wdir()
|
||||
d.SetDef(dir, green.regular("("+dir+")"))
|
||||
return nil
|
||||
},
|
||||
|
@ -374,7 +375,7 @@ func main() {
|
|||
if err != nil {
|
||||
return d.Err()
|
||||
}
|
||||
r.Schema[len(r.Schema)-1].Path = r.Settings.path(val)
|
||||
r.Schema[len(r.Schema)-1].Path = filepath.Clean(val)
|
||||
return nil
|
||||
},
|
||||
},
|
||||
|
@ -1045,7 +1046,7 @@ func main() {
|
|||
if err := r.Settings.record(r); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintln(output, prefix(green.bold(" Your configuration was successful")))
|
||||
log.Println(prefix(green.bold("Your configuration was successful")))
|
||||
return nil
|
||||
},
|
||||
Before: before,
|
||||
|
@ -1065,7 +1066,7 @@ func main() {
|
|||
if err := r.Settings.record(r); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintln(output, prefix(green.bold("Your project was successfully removed")))
|
||||
log.Println(prefix(green.bold("Your project was successfully removed")))
|
||||
return nil
|
||||
},
|
||||
Before: before,
|
||||
|
@ -1079,7 +1080,7 @@ func main() {
|
|||
if err := r.Settings.del(directory); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintln(output, prefix(green.bold("Realize folder successfully removed")))
|
||||
log.Println(prefix(green.bold("Realize folder successfully removed")))
|
||||
return nil
|
||||
},
|
||||
Before: before,
|
||||
|
@ -1087,7 +1088,7 @@ func main() {
|
|||
},
|
||||
}
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
fmt.Fprintln(output, prefix(red.bold(err)))
|
||||
log.Println(prefix(red.bold(err)))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
@ -1115,7 +1116,7 @@ func new() realize {
|
|||
// Prefix a given string
|
||||
func prefix(s string) string {
|
||||
if s != "" {
|
||||
return fmt.Sprint(yellow.bold("["), "REALIZE", yellow.bold("]"), s)
|
||||
return fmt.Sprint(yellow.bold("["), "REALIZE", yellow.bold("]"), " : ", s)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
@ -1143,7 +1144,16 @@ func before(*cli.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Wdir return current working directory
|
||||
func wdir() string {
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Fatal(prefix(err.Error()))
|
||||
}
|
||||
return dir
|
||||
}
|
||||
|
||||
// Rewrite the layout of the log timestamp
|
||||
func (w logWriter) Write(bytes []byte) (int, error) {
|
||||
return fmt.Fprint(output, yellow.regular("["), time.Now().Format("15:04:05"), yellow.regular("]")+string(bytes))
|
||||
return fmt.Fprint(output, yellow.regular("["), time.Now().Format("15:04:05"), yellow.regular("]"), string(bytes))
|
||||
}
|
||||
|
|
16
settings.go
16
settings.go
|
@ -7,7 +7,6 @@ import (
|
|||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
@ -102,11 +101,6 @@ func (s *Settings) del(d string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Path cleaner
|
||||
func (s Settings) path(path string) string {
|
||||
return strings.Replace(filepath.Clean(path), "\\", "/", -1)
|
||||
}
|
||||
|
||||
// Validate checks a fatal error
|
||||
func (s Settings) validate(err error) error {
|
||||
if err != nil {
|
||||
|
@ -171,16 +165,6 @@ func (s Settings) write(name string, data []byte) error {
|
|||
return s.validate(err)
|
||||
}
|
||||
|
||||
// Name return the project name or the path of the working dir
|
||||
func (s Settings) name(name string, path string) string {
|
||||
if name == "" && path == "" {
|
||||
return s.wdir()
|
||||
} else if path != "/" {
|
||||
return filepath.Base(path)
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
// Create a new file and return its pointer
|
||||
func (s Settings) create(path string, name string) *os.File {
|
||||
var file string
|
||||
|
|
Loading…
Reference in New Issue