summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/fileserver/command.go
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2023-02-24 18:09:12 -0500
committerGitHub <noreply@github.com>2023-02-24 16:09:12 -0700
commit9e6919550be5689628d0020ec14e90ea6f527716 (patch)
tree81865f63e5ef549f8548cd6e22e9aa89d4eaf207 /modules/caddyhttp/fileserver/command.go
parent167981d258f41b7ef931d510056a5a5fdc9cbd0d (diff)
cmd: Expand cobra support, add short flags (#5379)
* cmd: Expand cobra support * Convert commands to cobra, add short flags * Fix version command typo Co-authored-by: Emily Lange <git@indeednotjames.com> * Apply suggestions from code review Co-authored-by: Matt Holt <mholt@users.noreply.github.com> --------- Co-authored-by: Emily Lange <git@indeednotjames.com> Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
Diffstat (limited to 'modules/caddyhttp/fileserver/command.go')
-rw-r--r--modules/caddyhttp/fileserver/command.go24
1 files changed, 11 insertions, 13 deletions
diff --git a/modules/caddyhttp/fileserver/command.go b/modules/caddyhttp/fileserver/command.go
index bc7f981..697ec34 100644
--- a/modules/caddyhttp/fileserver/command.go
+++ b/modules/caddyhttp/fileserver/command.go
@@ -16,7 +16,6 @@ package fileserver
import (
"encoding/json"
- "flag"
"log"
"strconv"
"time"
@@ -27,13 +26,13 @@ import (
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
caddytpl "github.com/caddyserver/caddy/v2/modules/caddyhttp/templates"
"github.com/caddyserver/certmagic"
+ "github.com/spf13/cobra"
"go.uber.org/zap"
)
func init() {
caddycmd.RegisterCommand(caddycmd.Command{
Name: "file-server",
- Func: cmdFileServer,
Usage: "[--domain <example.com>] [--root <path>] [--listen <addr>] [--browse] [--access-log]",
Short: "Spins up a production-ready file server",
Long: `
@@ -49,17 +48,16 @@ using this option.
If --browse is enabled, requests for folders without an index file will
respond with a file listing.`,
- Flags: func() *flag.FlagSet {
- fs := flag.NewFlagSet("file-server", flag.ExitOnError)
- fs.String("domain", "", "Domain name at which to serve the files")
- fs.String("root", "", "The path to the root of the site")
- fs.String("listen", "", "The address to which to bind the listener")
- fs.Bool("browse", false, "Enable directory browsing")
- fs.Bool("templates", false, "Enable template rendering")
- fs.Bool("access-log", false, "Enable the access log")
- fs.Bool("debug", false, "Enable verbose debug logs")
- return fs
- }(),
+ CobraFunc: func(cmd *cobra.Command) {
+ cmd.Flags().StringP("domain", "d", "", "Domain name at which to serve the files")
+ cmd.Flags().StringP("root", "r", "", "The path to the root of the site")
+ cmd.Flags().StringP("listen", "", "", "The address to which to bind the listener")
+ cmd.Flags().BoolP("browse", "b", false, "Enable directory browsing")
+ cmd.Flags().BoolP("templates", "t", false, "Enable template rendering")
+ 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)
+ },
})
}