Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions cmd/commandfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,16 +441,20 @@ func cmdEnviron(fl Flags) (int, error) {
}

func cmdAdaptConfig(fl Flags) (int, error) {
inputFlag := fl.String("config")
configFlag := fl.String("config")
adapterFlag := fl.String("adapter")
prettyFlag := fl.Bool("pretty")
validateFlag := fl.Bool("validate")

var err error
inputFlag, err = configFileWithRespectToDefault(caddy.Log(), inputFlag)
configFlag, err = configFileWithRespectToDefault(caddy.Log(), configFlag)
if err != nil {
return caddy.ExitCodeFailedStartup, err
}
if configFlag == "" {
return caddy.ExitCodeFailedStartup,
fmt.Errorf("input file required when there is no Caddyfile in current directory (use --config flag)")
}

// load all additional envs as soon as possible
err = handleEnvFileFlag(fl)
Expand All @@ -469,13 +473,19 @@ func cmdAdaptConfig(fl Flags) (int, error) {
fmt.Errorf("unrecognized config adapter: %s", adapterFlag)
}

input, err := os.ReadFile(inputFlag)
var input []byte
// read from stdin if the file name is "-"
if configFlag == "-" {
input, err = io.ReadAll(os.Stdin)
} else {
input, err = os.ReadFile(configFlag)
}
if err != nil {
return caddy.ExitCodeFailedStartup,
fmt.Errorf("reading input file: %v", err)
}

opts := map[string]any{"filename": inputFlag}
opts := map[string]any{"filename": configFlag}

adaptedConfig, warnings, err := cfgAdapter.Adapt(input, opts)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ zero exit status will be returned.

If --envfile is specified, an environment file with environment variables
in the KEY=VALUE format will be loaded into the Caddy process.

If you wish to use stdin instead of a regular file, use - as the path.
`,
CobraFunc: func(cmd *cobra.Command) {
cmd.Flags().StringP("config", "c", "", "Configuration file to adapt (required)")
Expand Down Expand Up @@ -390,7 +392,7 @@ lines will be prefixed with '-' and '+' where they differ. Note that
unchanged lines are prefixed with two spaces for alignment, and that this
is not a valid patch format.

If you wish you use stdin instead of a regular file, use - as the path.
If you wish to use stdin instead of a regular file, use - as the path.
When reading from stdin, the --overwrite flag has no effect: the result
is always printed to stdout.
`,
Expand Down
Loading