package cli import ( "fileserver/version" "log" "net/http" "github.com/spf13/cobra" ) func cmdStart() (cmd *cobra.Command) { cmd = &cobra.Command{ Use: "start", Short: "Starts the Simple File Server with the given configuration.", Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { // Run the server log.Printf("Simple File Server v%s", version.VERSION) log.Printf("Compiled with Go %s", version.GetGoversion()) log.Printf("Configuration: root directory='%s', bind to='%s", configData.RootDirectory, configData.BindHostAndPort) log.Println("Start the file server now...") http.Handle("/", http.FileServer(http.Dir(configData.RootDirectory))) http.ListenAndServe(configData.BindHostAndPort, nil) }, } cmd.Flags().StringVarP(&configData.RootDirectory, "rootDirectory", "d", ".", "The root directory. All files in this directory and its sub-directories get published.") cmd.Flags().StringVarP(&configData.BindHostAndPort, "bindHostPort", "b", "0.0.0.0:8080", "The address or hostname and port where to bind the file server.") return }