check become a struct method
This commit is contained in:
parent
f295bfa544
commit
b8221695ba
@ -30,15 +30,14 @@ type Watcher struct{
|
|||||||
|
|
||||||
var file = "realize.config.yaml"
|
var file = "realize.config.yaml"
|
||||||
|
|
||||||
// Check files exists
|
// Check file exists and clean by duplicates
|
||||||
func Check(files ...string) (result []bool){
|
func (h *Config) Check() error{
|
||||||
for _, val := range files {
|
// clean duplicates
|
||||||
if _, err := ioutil.ReadFile(val); err == nil {
|
_, err := ioutil.ReadFile(h.file);
|
||||||
result = append(result,true)
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
result = append(result, false)
|
return nil
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default value
|
// Default value
|
||||||
@ -68,9 +67,9 @@ func (h *Config) Read() error{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create config yaml file
|
// Create config yaml file
|
||||||
func (h *Config) Create() error{
|
func (h *Config) Create(params *cli.Context) error{
|
||||||
config := Check(h.file)
|
h.Init(params)
|
||||||
if config[0] == false {
|
if h.Check() == nil {
|
||||||
if y, err := yaml.Marshal(h); err == nil {
|
if y, err := yaml.Marshal(h); err == nil {
|
||||||
err = ioutil.WriteFile(h.file, y, 0755)
|
err = ioutil.WriteFile(h.file, y, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -87,8 +86,7 @@ func (h *Config) Create() error{
|
|||||||
|
|
||||||
// Add another project
|
// Add another project
|
||||||
func (h *Config) Add(params *cli.Context) error{
|
func (h *Config) Add(params *cli.Context) error{
|
||||||
config := Check(file)
|
if h.Check() == nil {
|
||||||
if config[0] == true {
|
|
||||||
new := Project{
|
new := Project{
|
||||||
Main: params.String("main"),
|
Main: params.String("main"),
|
||||||
Run: params.Bool("run"),
|
Run: params.Bool("run"),
|
||||||
|
Loading…
Reference in New Issue
Block a user