@@ -334,12 +334,15 @@ func buildServe(cfg cliConfig) *cobra.Command {
334334 port := options .NewPortOption ()
335335 statusFlagName := "show-status"
336336 listFlagName := "list"
337+ staticFlagName := "static"
337338
338339 c := & cobra.Command {
339340 Use : "serve" ,
340341 Short : "Starts an HTTP server on localhost" ,
341- Long : `Starts an HTTP server on localhost.
342- Useful for local testing and debugging.` ,
342+ Long : `Starts an HTTP server on localhost. Useful for local testing.
343+
344+ If --static DIR is provided the server hosts the files
345+ in that directory. Otherwise the default API is started (use --list to see endoints).` ,
343346 Run : func (cmd * cobra.Command , args []string ) {
344347 flags := cmd .Flags ()
345348
@@ -350,10 +353,12 @@ Useful for local testing and debugging.`,
350353 }
351354
352355 showStatus , _ := flags .GetBool (statusFlagName )
356+ staticRoot , _ := flags .GetString (staticFlagName )
353357
354358 opts := server.Options {
355359 Port : port .Value (),
356360 ShowStatus : showStatus ,
361+ StaticRoot : staticRoot ,
357362 }
358363
359364 server := server .New (opts )
@@ -380,6 +385,7 @@ Useful for local testing and debugging.`,
380385 }
381386
382387 c .Flags ().VarP (port , "port" , "p" , "Port to listen on. Must be valid number in the range 1024-65535." )
388+ c .Flags ().String (staticFlagName , "" , "Serve static files from this directory." )
383389 c .Flags ().Bool (statusFlagName , false , "Shows current status instead of showing each request." )
384390 c .Flags ().Bool (listFlagName , false , "List predefined routes." )
385391 return c
0 commit comments