From 565226314bf9d09e84b17c616bd3845237fef294 Mon Sep 17 00:00:00 2001 From: Mohammed Al Sahaf Date: Thu, 13 Jul 2023 21:11:02 +0300 Subject: [PATCH] fileserver: add `export-template` sub-command to `file-server` --- modules/caddyhttp/fileserver/command.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/modules/caddyhttp/fileserver/command.go b/modules/caddyhttp/fileserver/command.go index 0112a5f6def..bccaf2f8e9d 100644 --- a/modules/caddyhttp/fileserver/command.go +++ b/modules/caddyhttp/fileserver/command.go @@ -16,7 +16,9 @@ package fileserver import ( "encoding/json" + "io" "log" + "os" "strconv" "time" @@ -57,6 +59,15 @@ respond with a file listing.`, cmd.Flags().BoolP("access-log", "", false, "Enable the access log") cmd.Flags().BoolP("debug", "v", false, "Enable verbose debug logs") cmd.RunE = caddycmd.WrapCommandFuncForCobra(cmdFileServer) + cmd.AddCommand(&cobra.Command{ + Use: "export-template", + Short: "Exports the default file browser template", + Example: "caddy file-server export-template > browse.html", + RunE: func(cmd *cobra.Command, args []string) error { + _, err := io.WriteString(os.Stdout, defaultBrowseTemplate) + return err + }, + }) }, }) }