cmd: Add caddy fmt command. (#3090)

This takes the config file as input and formats it.
Prints the result to stdout. Can write changes to
file if `--write` flag is passed.

Fixes #3020

Signed-off-by: Vaibhav <vrongmeal@gmail.com>
This commit is contained in:
Vaibhav
2020-02-29 22:42:16 +05:30
committed by GitHub
parent e717028f83
commit 5fe69ac4ab
4 changed files with 346 additions and 0 deletions

View File

@ -242,6 +242,24 @@ provisioning stages.`,
}(),
})
RegisterCommand(Command{
Name: "fmt",
Func: cmdFormatConfig,
Usage: "[--write] [<path>]",
Short: "Formats a Caddyfile",
Long: `
Formats the Caddyfile by adding proper indentation and spaces to improve
human readability. It prints the result to stdout.
If --write is specified, the output will be written to the config file
directly instead of printing it.`,
Flags: func() *flag.FlagSet {
fs := flag.NewFlagSet("format", flag.ExitOnError)
fs.Bool("write", false, "Over-write the output to specified file")
return fs
}(),
})
}
// RegisterCommand registers the command cmd.