1
0
mirror of https://github.com/drone/drone-cli.git synced 2026-01-24 11:48:01 +01:00
drone-cli/drone/format/format.go

40 lines
699 B
Go
Raw Normal View History

2018-09-14 03:41:12 +02:00
package format
import (
"bytes"
"io"
"io/ioutil"
"os"
"github.com/urfave/cli"
)
// Command exports the fmt command.
var Command = cli.Command{
Name: "fmt",
Usage: "<deprecated. this operation is a no-op> format the yaml file",
2018-09-14 03:41:12 +02:00
ArgsUsage: "<source>",
Hidden: true,
2018-09-14 03:41:12 +02:00
Action: format,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "save",
Usage: "save result to source",
},
},
}
func format(c *cli.Context) error {
path := c.Args().First()
if path == "" {
path = ".drone.yml"
}
out, _ := ioutil.ReadFile(path)
buf := bytes.NewBuffer(out)
2018-09-14 03:41:12 +02:00
if c.Bool("save") {
return ioutil.WriteFile(path, buf.Bytes(), 0644)
}
_, err := io.Copy(os.Stderr, buf)
2018-09-14 03:41:12 +02:00
return err
}