mirror of
https://github.com/caddyserver/caddy.git
synced 2025-03-23 05:49:27 +01:00
cmd: fmt: --write -> --overwrite to make it clear it's destructive
This commit is contained in:
parent
8f8ecd2e2a
commit
c67c8e60cc
2 changed files with 6 additions and 8 deletions
|
@ -514,14 +514,12 @@ func cmdValidateConfig(fl Flags) (int, error) {
|
||||||
return caddy.ExitCodeSuccess, nil
|
return caddy.ExitCodeSuccess, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func cmdFormatConfig(fl Flags) (int, error) {
|
func cmdFmt(fl Flags) (int, error) {
|
||||||
// Default path of file is Caddyfile
|
|
||||||
formatCmdConfigFile := fl.Arg(0)
|
formatCmdConfigFile := fl.Arg(0)
|
||||||
if formatCmdConfigFile == "" {
|
if formatCmdConfigFile == "" {
|
||||||
formatCmdConfigFile = "Caddyfile"
|
formatCmdConfigFile = "Caddyfile"
|
||||||
}
|
}
|
||||||
|
overwrite := fl.Bool("overwrite")
|
||||||
formatCmdWriteFlag := fl.Bool("write")
|
|
||||||
|
|
||||||
input, err := ioutil.ReadFile(formatCmdConfigFile)
|
input, err := ioutil.ReadFile(formatCmdConfigFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -531,7 +529,7 @@ func cmdFormatConfig(fl Flags) (int, error) {
|
||||||
|
|
||||||
output := caddyfile.Format(input)
|
output := caddyfile.Format(input)
|
||||||
|
|
||||||
if formatCmdWriteFlag {
|
if overwrite {
|
||||||
err = ioutil.WriteFile(formatCmdConfigFile, output, 0644)
|
err = ioutil.WriteFile(formatCmdConfigFile, output, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return caddy.ExitCodeFailedStartup, nil
|
return caddy.ExitCodeFailedStartup, nil
|
||||||
|
|
|
@ -244,8 +244,8 @@ provisioning stages.`,
|
||||||
|
|
||||||
RegisterCommand(Command{
|
RegisterCommand(Command{
|
||||||
Name: "fmt",
|
Name: "fmt",
|
||||||
Func: cmdFormatConfig,
|
Func: cmdFmt,
|
||||||
Usage: "[--write] [<path>]",
|
Usage: "[--overwrite] [<path>]",
|
||||||
Short: "Formats a Caddyfile",
|
Short: "Formats a Caddyfile",
|
||||||
Long: `
|
Long: `
|
||||||
Formats the Caddyfile by adding proper indentation and spaces to improve
|
Formats the Caddyfile by adding proper indentation and spaces to improve
|
||||||
|
@ -255,7 +255,7 @@ If --write is specified, the output will be written to the config file
|
||||||
directly instead of printing it.`,
|
directly instead of printing it.`,
|
||||||
Flags: func() *flag.FlagSet {
|
Flags: func() *flag.FlagSet {
|
||||||
fs := flag.NewFlagSet("format", flag.ExitOnError)
|
fs := flag.NewFlagSet("format", flag.ExitOnError)
|
||||||
fs.Bool("write", false, "Over-write the output to specified file")
|
fs.Bool("overwrite", false, "Overwrite the input file with the results")
|
||||||
return fs
|
return fs
|
||||||
}(),
|
}(),
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue