mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
Improvements to fmt (#1076)
* fmt should include newline at end * fmt should use stderr
This commit is contained in:
@@ -2,9 +2,11 @@ package commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/ditashi/jsbeautifier-go/jsbeautifier"
|
"github.com/ditashi/jsbeautifier-go/jsbeautifier"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"io/ioutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = cmd(catUtils, func() *cli.Command {
|
var _ = cmd(catUtils, func() *cli.Command {
|
||||||
@@ -56,11 +58,15 @@ func FmtFile(args FmtArgs) error {
|
|||||||
return beautifyErr
|
return beautifyErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(beautified) != 0 && beautified[len(beautified)-1] != '\n' {
|
||||||
|
beautified = beautified + "\n"
|
||||||
|
}
|
||||||
|
|
||||||
if args.OutputFile != "" {
|
if args.OutputFile != "" {
|
||||||
if err := ioutil.WriteFile(args.OutputFile, []byte(beautified), 0744); err != nil {
|
if err := ioutil.WriteFile(args.OutputFile, []byte(beautified), 0744); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("File %s successfully written\n", args.OutputFile)
|
fmt.Fprintf(os.Stderr, "File %s successfully written\n", args.OutputFile)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Print(beautified)
|
fmt.Print(beautified)
|
||||||
|
|||||||
Reference in New Issue
Block a user