fixing help message printing
This commit is contained in:
@@ -38,7 +38,10 @@ func (c *Command) Name() string {
|
||||
}
|
||||
|
||||
func (c *Command) Usage() {
|
||||
fmt.Fprintf(os.Stderr, "Usage: %s\n", c.UsageLine)
|
||||
fmt.Fprintf(os.Stderr, "Example: weed %s\n", c.UsageLine)
|
||||
fmt.Fprintf(os.Stderr, "Default Usage:\n")
|
||||
c.Flag.PrintDefaults()
|
||||
fmt.Fprintf(os.Stderr, "Description:\n")
|
||||
fmt.Fprintf(os.Stderr, " %s\n", strings.TrimSpace(c.Long))
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"pkg/storage"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -30,6 +31,7 @@ var (
|
||||
capacity = cmdMaster.Flag.Int("capacity", 100, "maximum number of volumes to hold")
|
||||
mapper *directory.Mapper
|
||||
volumeSizeLimitMB = cmdMaster.Flag.Uint("volumeSizeLimitMB", 32*1024, "Default Volume Size in MegaBytes")
|
||||
mpulse = cmdMaster.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats")
|
||||
)
|
||||
|
||||
func dirLookupHandler(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -64,7 +66,7 @@ func dirJoinHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if *IsDebug {
|
||||
log.Println(s, "volumes", r.FormValue("volumes"))
|
||||
}
|
||||
mapper.Add(directory.NewMachine(s, publicUrl, *volumes))
|
||||
mapper.Add(directory.NewMachine(s, publicUrl, *volumes, time.Now().Unix()))
|
||||
}
|
||||
func dirStatusHandler(w http.ResponseWriter, r *http.Request) {
|
||||
writeJson(w, r, mapper)
|
||||
@@ -72,7 +74,7 @@ func dirStatusHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func runMaster(cmd *Command, args []string) bool {
|
||||
log.Println("Volume Size Limit is", *volumeSizeLimitMB, "MB")
|
||||
mapper = directory.NewMapper(*metaFolder, "directory", uint64(*volumeSizeLimitMB)*1024*1024)
|
||||
mapper = directory.NewMapper(*metaFolder, "directory", uint64(*volumeSizeLimitMB)*1024*1024, *mpulse)
|
||||
http.HandleFunc("/dir/assign", dirAssignHandler)
|
||||
http.HandleFunc("/dir/lookup", dirLookupHandler)
|
||||
http.HandleFunc("/dir/join", dirJoinHandler)
|
||||
|
||||
@@ -25,12 +25,12 @@ var cmdVolume = &Command{
|
||||
}
|
||||
|
||||
var (
|
||||
vport = cmdVolume.Flag.Int("port", 8080, "http listen port")
|
||||
vport = cmdVolume.Flag.Int("port", 8080, "http listen port")
|
||||
chunkFolder = cmdVolume.Flag.String("dir", "/tmp", "data directory to store files")
|
||||
volumes = cmdVolume.Flag.String("volumes", "0,1-3,4", "comma-separated list of volume ids or range of ids")
|
||||
publicUrl = cmdVolume.Flag.String("publicUrl", "localhost:8080", "public url to serve data read")
|
||||
metaServer = cmdVolume.Flag.String("mserver", "localhost:9333", "master directory server to store mappings")
|
||||
pulse = cmdVolume.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats")
|
||||
vpulse = cmdVolume.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats")
|
||||
|
||||
store *storage.Store
|
||||
)
|
||||
@@ -85,7 +85,7 @@ func GetHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
func PostHandler(w http.ResponseWriter, r *http.Request) {
|
||||
vid, _, _ := parseURLPath(r.URL.Path)
|
||||
volumeId, e := storage.NewVolumeId(vid)
|
||||
volumeId, e := storage.NewVolumeId(vid)
|
||||
if e != nil {
|
||||
writeJson(w, r, e)
|
||||
} else {
|
||||
@@ -103,7 +103,7 @@ func PostHandler(w http.ResponseWriter, r *http.Request) {
|
||||
func DeleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||
n := new(storage.Needle)
|
||||
vid, fid, _ := parseURLPath(r.URL.Path)
|
||||
volumeId, _ := storage.NewVolumeId(vid)
|
||||
volumeId, _ := storage.NewVolumeId(vid)
|
||||
n.ParsePath(fid)
|
||||
|
||||
if *IsDebug {
|
||||
@@ -162,7 +162,7 @@ func runVolume(cmd *Command, args []string) bool {
|
||||
go func() {
|
||||
for {
|
||||
store.Join(*metaServer)
|
||||
time.Sleep(time.Duration(float32(*pulse*1e3)*(1+rand.Float32())) * time.Millisecond)
|
||||
time.Sleep(time.Duration(float32(*vpulse*1e3)*(1+rand.Float32())) * time.Millisecond)
|
||||
}
|
||||
}()
|
||||
log.Println("store joined at", *metaServer)
|
||||
|
||||
@@ -52,7 +52,7 @@ func main() {
|
||||
if args[0] == "help" {
|
||||
help(args[1:])
|
||||
for _, cmd := range commands {
|
||||
if len(args)>2 && cmd.Name() == args[1] && cmd.Run != nil {
|
||||
if len(args)>=2 && cmd.Name() == args[1] && cmd.Run != nil {
|
||||
fmt.Fprintf(os.Stderr, "Default Parameters:\n")
|
||||
cmd.Flag.PrintDefaults()
|
||||
}
|
||||
@@ -93,12 +93,6 @@ The commands are:
|
||||
|
||||
Use "weed help [command]" for more information about a command.
|
||||
|
||||
Additional help topics:
|
||||
{{range .}}{{if not .Runnable}}
|
||||
{{.Name | printf "%-11s"}} {{.Short}}{{end}}{{end}}
|
||||
|
||||
Use "weed help [topic]" for more information about that topic.
|
||||
|
||||
`
|
||||
|
||||
var helpTemplate = `{{if .Runnable}}Usage: weed {{.UsageLine}}
|
||||
|
||||
Reference in New Issue
Block a user