mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-13 22:38:04 +00:00
Added cli niceness
This commit is contained in:
parent
c4bc70955e
commit
da31cbe672
24
yaml.go
24
yaml.go
@ -5,10 +5,32 @@ import (
|
|||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
"log"
|
"log"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"github.com/codegangsta/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var raw_data, read_error = ioutil.ReadFile("sample.yaml")
|
app := cli.NewApp()
|
||||||
|
app.Name = "yaml"
|
||||||
|
app.Usage = "command line tool for reading and writing yaml"
|
||||||
|
app.Commands = []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "read",
|
||||||
|
Aliases: []string{"r"},
|
||||||
|
Usage: "(default) reads a property from a given yaml file",
|
||||||
|
Action: read_file,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
app.Action = read_file
|
||||||
|
app.Run(os.Args)
|
||||||
|
}
|
||||||
|
|
||||||
|
func read_file(c *cli.Context) {
|
||||||
|
if len(c.Args()) == 0 {
|
||||||
|
log.Fatalf("Must provide filename")
|
||||||
|
}
|
||||||
|
var filename = c.Args()[0]
|
||||||
|
var raw_data, read_error = ioutil.ReadFile(filename)
|
||||||
|
|
||||||
if read_error != nil {
|
if read_error != nil {
|
||||||
log.Fatalf("error: %v", read_error)
|
log.Fatalf("error: %v", read_error)
|
||||||
|
Loading…
Reference in New Issue
Block a user