yaml write

This commit is contained in:
alessio 2016-07-12 12:14:54 +02:00
parent 55600eac85
commit 91110c5e02
3 changed files with 52 additions and 50 deletions

View File

@ -7,3 +7,6 @@ import:
- package: gopkg.in/urfave/cli.v2 - package: gopkg.in/urfave/cli.v2
version: ^1.18.0 version: ^1.18.0
- package: gopkg.in/yaml.v2 - package: gopkg.in/yaml.v2
- package: github.com/tockins/realize
subpackages:
- realize

82
main.go
View File

@ -1,55 +1,47 @@
package main package main
import ( import (
"os" //"os"
"gopkg.in/urfave/cli.v2" //"gopkg.in/urfave/cli.v2"
"fmt" "github.com/tockins/realize/realize"
"github.com/labstack/echo"
"net/http"
"gopkg.in/yaml.v2"
"github.com/labstack/echo/engine/standard"
"realize"
) )
func main() { func main() {
t := realize.Config{App_file:"realize.config.yml"} t := realize.Config{
App_file:"realize.config.yaml",
App_version:"1.0",
App_main:[]string{"main.go"},
}
t.Create() t.Create()
app := &cli.App{ //app := &cli.App{
Name: "realize", // Name: "realize",
Version: "1.0", // Version: "1.0",
Usage: "A sort of Webpack for Go. Run, build and watch file changes with custom paths", // Usage: "A sort of Webpack for Go. Run, build and watch file changes with custom paths",
Commands: []*cli.Command{ // Commands: []*cli.Command{
{ // {
Name: "run", // Name: "run",
Usage: "Build and watch file changes", // Usage: "Build and watch file changes",
Action: func(c *cli.Context) error { // Action: func(c *cli.Context) error {
fmt.Printf("Hello %q", c.String("run")) // fmt.Printf("Hello %q", c.String("run"))
return nil // return nil
}, // },
}, // },
{ // {
Name: "start", // Name: "start",
Category: "config", // Category: "config",
Usage: "create the initial config file", // Usage: "create the initial config file",
}, // },
}, // },
Flags: []cli.Flag { // Flags: []cli.Flag {
&cli.StringFlag{ // &cli.StringFlag{
Name: "run", // Name: "run",
Value: "main.go", // Value: "main.go",
Usage: "main file of your project", // Usage: "main file of your project",
}, // },
}, // },
} //}
//
app.Run(os.Args) //app.Run(os.Args)
// web server
e := echo.New()
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})
e.Run(standard.New("0.0.0.0:8080"))
} }

View File

@ -2,14 +2,15 @@ package realize
import ( import (
"os" "os"
"gopkg.in/yaml.v2"
) )
type Config struct { type Config struct {
App_file string App_file string
app_main []string App_main []string
app_version string App_version string
app_build bool App_build bool
app_run struct { App_run struct {
before, after, paths, ext []string before, after, paths, ext []string
} }
} }
@ -18,7 +19,13 @@ type Config struct {
func (h *Config) Create() bool{ func (h *Config) Create() bool{
var config = Check(h.App_file) var config = Check(h.App_file)
if config[0] == false { if config[0] == false {
if _, err := os.Create("realize.config.yml"); err == nil { if w, err := os.Create(h.App_file); err == nil {
y, err := yaml.Marshal(&h)
w.WriteString(string(y))
if err != nil {
defer panic(err)
}
w.Close()
return true return true
}else{ }else{
panic(err) panic(err)