@@ -8,30 +8,27 @@ import (
88 "github.com/spf13/cobra"
99)
1010
11- var path string
1211var address string
1312var port int
1413
1514func init () {
16- Cmd .Flags ().StringVarP (& path , "dir" , "d" , "./" , "Directory to serve" )
1715 Cmd .Flags ().StringVarP (& address , "address" , "a" , "" , "Address to listen on" )
1816 Cmd .Flags ().IntVarP (& port , "port" , "p" , 8000 , "Post to listen on" )
1917}
2018
21- func serveHelp () {
22- fmt .Println ("Usage: please serve <PATH> [<ADDRESS>[:<PORT>]]" )
23- fmt .Println ()
24- fmt .Println ("Serves the contents of PATH on the specified address and port." )
25- fmt .Println ("Requested paths will be printed to stdout." )
26- }
27-
2819var Cmd = & cobra.Command {
29- Use : "serve" ,
30- Short : "Serve the contents of a directory through a simple web server" ,
20+ Use : "serve (PATH)" ,
21+ Short : "Serve the contents of PATH (current directory if omitted) through a simple web server" ,
22+ Args : cobra .RangeArgs (0 , 1 ),
3123 Run : func (cmd * cobra.Command , args []string ) {
24+ path := "./"
25+ if len (args ) == 1 {
26+ path = args [0 ]
27+ }
28+
3229 address = fmt .Sprintf ("%s:%d" , address , port )
3330
34- fmt .Println ( "Listening on" , address )
31+ fmt .Printf ( "Serving %s on %s \n " , path , address )
3532
3633 fsys := loggingFileSystem {http .Dir (path )}
3734
0 commit comments