fix list
This commit is contained in:
parent
85e6f0028c
commit
3868698296
|
@ -6,65 +6,32 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"gopkg.in/urfave/cli.v2"
|
"gopkg.in/urfave/cli.v2"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"github.com/fatih/color"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const(
|
|
||||||
file = "realize.config.yaml"
|
|
||||||
ext = ".go"
|
|
||||||
path = "/"
|
|
||||||
ignore = "vendor"
|
|
||||||
)
|
|
||||||
|
|
||||||
var green = color.New(color.FgGreen, color.Bold).SprintFunc()
|
|
||||||
var greenl = color.New(color.FgHiGreen).SprintFunc()
|
|
||||||
var red = color.New(color.FgRed).SprintFunc()
|
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
file string
|
file string
|
||||||
Version string `yaml:"version,omitempty"`
|
Version string `yaml:"version,omitempty"`
|
||||||
Projects []Project
|
Projects []Project
|
||||||
}
|
}
|
||||||
|
|
||||||
type Project struct {
|
|
||||||
base string
|
|
||||||
reload time.Time
|
|
||||||
Name string `yaml:"app_name,omitempty"`
|
|
||||||
Run bool `yaml:"app_run,omitempty"`
|
|
||||||
Bin bool `yaml:"app_bin,omitempty"`
|
|
||||||
Build bool `yaml:"app_build,omitempty"`
|
|
||||||
Main string `yaml:"app_main,omitempty"`
|
|
||||||
Watcher Watcher `yaml:"app_watcher,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Watcher struct{
|
|
||||||
// different before and after on rerun?
|
|
||||||
Before []string `yaml:"before,omitempty"`
|
|
||||||
After []string `yaml:"after,omitempty"`
|
|
||||||
Paths []string `yaml:"paths,omitempty"`
|
|
||||||
Ignore []string `yaml:"ignore_paths,omitempty"`
|
|
||||||
Exts []string `yaml:"exts,omitempty"`
|
|
||||||
Preview bool `yaml:"preview,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default value
|
// Default value
|
||||||
func New(params *cli.Context) *Config{
|
func New(params *cli.Context) *Config{
|
||||||
return &Config{
|
return &Config{
|
||||||
file: file,
|
file: app_file,
|
||||||
Version: "1.0",
|
Version: "1.0",
|
||||||
Projects: []Project{
|
Projects: []Project{
|
||||||
{
|
{
|
||||||
Name: params.String("name"),
|
Name: params.String("name"),
|
||||||
Main: params.String("main"),
|
Main: params.String("main"),
|
||||||
|
Path: params.String("base"),
|
||||||
Run: params.Bool("run"),
|
Run: params.Bool("run"),
|
||||||
Build: params.Bool("build"),
|
Build: params.Bool("build"),
|
||||||
Bin: params.Bool("bin"),
|
Bin: params.Bool("bin"),
|
||||||
Watcher: Watcher{
|
Watcher: Watcher{
|
||||||
Paths: []string{path},
|
Paths: []string{watcher_path},
|
||||||
Ignore: []string{ignore},
|
Ignore: []string{watcher_ignore},
|
||||||
Exts: []string{ext},
|
Exts: []string{watcher_ext},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -136,12 +103,13 @@ func (h *Config) Add(params *cli.Context) error{
|
||||||
new := Project{
|
new := Project{
|
||||||
Name: params.String("name"),
|
Name: params.String("name"),
|
||||||
Main: params.String("main"),
|
Main: params.String("main"),
|
||||||
|
Path: params.String("base"),
|
||||||
Run: params.Bool("run"),
|
Run: params.Bool("run"),
|
||||||
Build: params.Bool("build"),
|
Build: params.Bool("build"),
|
||||||
Watcher: Watcher{
|
Watcher: Watcher{
|
||||||
Paths: []string{path},
|
Paths: []string{watcher_path},
|
||||||
Exts: []string{ext},
|
Exts: []string{watcher_ext},
|
||||||
Ignore: []string{ignore},
|
Ignore: []string{watcher_ignore},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if Duplicates(new, h.Projects) {
|
if Duplicates(new, h.Projects) {
|
||||||
|
@ -172,10 +140,10 @@ func (h *Config) Remove(params *cli.Context) error{
|
||||||
// List of projects
|
// List of projects
|
||||||
func (h *Config) List() error{
|
func (h *Config) List() error{
|
||||||
if err := h.Read(); err == nil {
|
if err := h.Read(); err == nil {
|
||||||
red := color.New(color.FgRed).SprintFunc()
|
|
||||||
for _, val := range h.Projects {
|
for _, val := range h.Projects {
|
||||||
fmt.Println(green("|"), green(val.Name))
|
fmt.Println(green("|"), green(val.Name))
|
||||||
fmt.Println(greenl("|"),"\t", green("Main Path:"), red(val.Main))
|
fmt.Println(greenl("|"),"\t", green("Main File:"), red(val.Main))
|
||||||
|
fmt.Println(greenl("|"),"\t", green("Base Path:"), red(val.Path))
|
||||||
fmt.Println(greenl("|"),"\t", green("Run:"), red(val.Run))
|
fmt.Println(greenl("|"),"\t", green("Run:"), red(val.Run))
|
||||||
fmt.Println(greenl("|"),"\t", green("Build:"), red(val.Build))
|
fmt.Println(greenl("|"),"\t", green("Build:"), red(val.Build))
|
||||||
fmt.Println(greenl("|"),"\t", green("Watcher:"))
|
fmt.Println(greenl("|"),"\t", green("Watcher:"))
|
||||||
|
|
Loading…
Reference in New Issue