Commit 098dbccd authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent af34e00a
...@@ -19,17 +19,14 @@ ...@@ -19,17 +19,14 @@
package main package main
import ( import (
"flag"
"fmt"
"os"
"../../zodbtools" "../../zodbtools"
) )
var commandv = []Command{
// TODO analyze ?
// TODO cmp
{"dump", zodbtools.DumpMain},
{"info", zodbtools.InfoMain},
}
func usage() { func usage() {
w := os.Stderr w := os.Stderr
fmt.Fprintf(w, fmt.Fprintf(w,
...@@ -40,10 +37,11 @@ Usage: ...@@ -40,10 +37,11 @@ Usage:
zodb command [arguments] zodb command [arguments]
The commands are: The commands are:
`) `)
// TODO print commands // TODO print commands
for _, cmd := range zodbtools.AllCommands() { for _, cmd := range zodbtools.AllCommands() {
fmt.Fprintf(w, "\t%s\t%s\n", cmd.Name, cmd.Summary) fmt.Fprintf(w, "\t%-11s %s\n", cmd.Name, cmd.Summary)
} }
fmt.Fprintf(w, fmt.Fprintf(w,
...@@ -74,12 +72,16 @@ func help(argv []string) { ...@@ -74,12 +72,16 @@ func help(argv []string) {
topic := argv[1] topic := argv[1]
// topic can either be a command name or a help topic // topic can either be a command name or a help topic
command -> usage(os.Stdout) command := zodbtools.LookupCommand(topic)
if command != nil {
command.Usage(os.Stdout)
os.Exit(0)
}
// TODO topic // TODO topic
fmt.Fprintf(os.Stderr, "Unknown help topic `%s`. Run 'zodb help'.", topic) fmt.Fprintf(os.Stderr, "Unknown help topic `%s`. Run 'zodb help'.\n", topic)
os.Exit(2) os.Exit(2)
} }
...@@ -93,7 +95,7 @@ func main() { ...@@ -93,7 +95,7 @@ func main() {
os.Exit(2) os.Exit(2)
} }
command = argv[0] command := argv[0]
// help on a topic // help on a topic
if command == "help" { if command == "help" {
...@@ -102,8 +104,8 @@ func main() { ...@@ -102,8 +104,8 @@ func main() {
} }
// run subcommand // run subcommand
cmd, ok := commandDir[command] cmd := zodbtools.LookupCommand(command)
if !ok { if cmd == nil {
fmt.Fprintf(os.Stderr, "zodb: unknown subcommand \"%s\"", command) fmt.Fprintf(os.Stderr, "zodb: unknown subcommand \"%s\"", command)
fmt.Fprintf(os.Stderr, "Run 'zodb help' for usage.") fmt.Fprintf(os.Stderr, "Run 'zodb help' for usage.")
os.Exit(2) os.Exit(2)
......
...@@ -222,12 +222,12 @@ Options: ...@@ -222,12 +222,12 @@ Options:
func dumpMain(argv []string) { func dumpMain(argv []string) {
hashOnly := false hashOnly := false
tidRange := ".." // (0, +inf) tidRange := ".." // [0, +inf]
flags := flag.FlagSet{Usage: func() { dumpUsage(os.Stderr) }} flags := flag.FlagSet{Usage: func() { dumpUsage(os.Stderr) }}
flags.Init("", flag.ExitOnError) flags.Init("", flag.ExitOnError)
flags.BoolVar(&hashOnly, "hashonly", hashOnly, "dump only hashes of objects") flags.BoolVar(&hashOnly, "hashonly", hashOnly, "dump only hashes of objects")
flags.Parse(argv) flags.Parse(argv[1:])
argv = flags.Args() argv = flags.Args()
if len(argv) < 1 { if len(argv) < 1 {
......
...@@ -40,7 +40,7 @@ var infov = []struct {name string; getParam paramFunc} { ...@@ -40,7 +40,7 @@ var infov = []struct {name string; getParam paramFunc} {
} }
// {} parameter_name -> get_parameter(stor) // {} parameter_name -> get_parameter(stor)
var infoDict map[string]paramFunc var infoDict = map[string]paramFunc{}
func init() { func init() {
for _, info := range infov { for _, info := range infov {
...@@ -103,7 +103,7 @@ Options: ...@@ -103,7 +103,7 @@ Options:
func infoMain(argv []string) { func infoMain(argv []string) {
flags := flag.FlagSet{Usage: func() { infoUsage(os.Stderr) }} flags := flag.FlagSet{Usage: func() { infoUsage(os.Stderr) }}
flags.Init("", flag.ExitOnError) flags.Init("", flag.ExitOnError)
flags.Parse(argv) flags.Parse(argv[1:])
argv = flags.Args() argv = flags.Args()
if len(argv) < 1 { if len(argv) < 1 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment