Commit 62dc2806 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e2266200
......@@ -22,6 +22,8 @@ import (
"flag"
"fmt"
"os"
"../../../neo"
)
func usage() {
......@@ -36,31 +38,56 @@ Usage:
The commands are:
`)
for _, cmd := range zodbtools.AllCommands() {
for _, cmd := range neo.Commands {
fmt.Fprintf(w, "\t%-11s %s\n", cmd.Name, cmd.Summary)
}
fmt.Fprintf(w,
`
Use "zodb help [command]" for more information about a command.
Use "neo help [command]" for more information about a command.
Additional help topics:
`)
for _, topic := range zodbtools.AllHelpTopics() {
for _, topic := range neo.HelpTopics {
fmt.Fprintf(w, "\t%-11s %s\n", topic.Name, topic.Summary)
}
fmt.Fprintf(w,
`
Use "zodb help [topic]" for more information about that topic.
Use "neo help [topic]" for more information about that topic.
`)
}
// TODO help()
// help shows general help or help for a command/topic
func help(argv []string) {
if len(argv) < 2 { // help topic ...
usage()
os.Exit(2)
}
topic := argv[1]
// topic can either be a command name or a help topic
command := neo.Commands.Lookup(topic)
if command != nil {
command.Usage(os.Stdout)
os.Exit(0)
}
helpTopic := neo.HelpTopics.Lookup(topic)
if helpTopic != nil {
fmt.Println(helpTopic.Text)
os.Exit(0)
}
fmt.Fprintf(os.Stderr, "Unknown help topic `%s`. Run 'neo help'.\n", topic)
os.Exit(2)
}
func main() {
flag.Usage = usage
......@@ -81,10 +108,10 @@ func main() {
}
// run subcommand
cmd := zodbtools.LookupCommand(command)
cmd := neo.Commands.Lookup(command)
if cmd == nil {
fmt.Fprintf(os.Stderr, "zodb: unknown subcommand \"%s\"", command)
fmt.Fprintf(os.Stderr, "Run 'zodb help' for usage.")
fmt.Fprintf(os.Stderr, "neo: unknown subcommand \"%s\"", command)
fmt.Fprintf(os.Stderr, "Run 'neo help' for usage.")
os.Exit(2)
}
......
// Copyright (C) 2017 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Open Source Initiative approved licenses and Convey
// the resulting work. Corresponding source of such a combination shall include
// the source code for all other software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
package neo
// registry of all commands & help topics
import "../zodb/zodbtools"
var Commands = zodbtools.CommandRegistry{
{"storage", storageSummary, storageUsage, storageMain},
}
var HelpTopics = zodbtools.HelpRegistry{
// XXX for now empty
}
......@@ -40,7 +40,7 @@ Usage:
The commands are:
`)
for _, cmd := range zodbtools.AllCommands() {
for _, cmd := range zodbtools.Commands {
fmt.Fprintf(w, "\t%-11s %s\n", cmd.Name, cmd.Summary)
}
......@@ -53,7 +53,7 @@ Additional help topics:
`)
for _, topic := range zodbtools.AllHelpTopics() {
for _, topic := range zodbtools.HelpTopics {
fmt.Fprintf(w, "\t%-11s %s\n", topic.Name, topic.Summary)
}
......@@ -75,13 +75,13 @@ func help(argv []string) {
topic := argv[1]
// topic can either be a command name or a help topic
command := zodbtools.LookupCommand(topic)
command := zodbtools.Commands.Lookup(topic)
if command != nil {
command.Usage(os.Stdout)
os.Exit(0)
}
helpTopic := zodbtools.LookupHelpTopic(topic)
helpTopic := zodbtools.HelpTopics.Lookup(topic)
if helpTopic != nil {
fmt.Println(helpTopic.Text)
os.Exit(0)
......@@ -110,7 +110,7 @@ func main() {
}
// run subcommand
cmd := zodbtools.LookupCommand(command)
cmd := zodbtools.Commands.Lookup(command)
if cmd == nil {
fmt.Fprintf(os.Stderr, "zodb: unknown subcommand \"%s\"", command)
fmt.Fprintf(os.Stderr, "Run 'zodb help' for usage.")
......
......@@ -28,17 +28,11 @@ type Command struct {
Main func (argv []string)
}
// registry of all commands
var cmdv = []Command{
// NOTE the order commands are listed here is the order how they will appear in help
// TODO analyze ?
// TODO cmp
{"dump", dumpSummary, dumpUsage, dumpMain},
{"info", infoSummary, infoUsage, infoMain},
}
// CommandRegistry is ordered collection of Commands
type CommandRegistry []Command
// LookupCommand returns Command with corresponding name or nil
func LookupCommand(command string) *Command {
// Lookup returns Command with corresponding name or nil
func (cmdv CommandRegistry) Lookup(command string) *Command {
for i := range cmdv {
if cmdv[i].Name == command {
return &cmdv[i]
......@@ -47,7 +41,11 @@ func LookupCommand(command string) *Command {
return nil
}
// AllCommands returns list of all zodbtools commands
func AllCommands() []Command {
return cmdv
// registry of all zodbtools commands
var Commands = CommandRegistry{
// NOTE the order commands are listed here is the order how they will appear in help
// TODO analyze ?
// TODO cmp
{"dump", dumpSummary, dumpUsage, dumpMain},
{"info", infoSummary, infoUsage, infoMain},
}
......@@ -18,12 +18,26 @@
package zodbtools
// registry for all help topics
// HelpTopic describes one help topic
type HelpTopic struct {
Name string
Summary string
Text string
}
// HelpRegistry is ordered collection of HelpTopics
type HelpRegistry []HelpTopic
// Lookup returns HelpTopic with corresponding name or nil
func (helpv HelpRegistry) Lookup(topic string) *HelpTopic {
for i := range helpv {
if helpv[i].Name == topic {
return &helpv[i]
}
}
return nil
}
const helpZURL =
`Almost every zodb command works with a database.
A database can be specified by way of providing URL for its storage.
......@@ -52,21 +66,6 @@ Please see zodburi documentation for full details:
http://docs.pylonsproject.org/projects/zodburi/
`
var helpv = []HelpTopic{
var HelpTopics = HelpRegistry{
{"zurl", "specifying database URL", helpZURL},
}
// LookupHelpTopic returns HelpTopic with corresponding name or nil
func LookupHelpTopic(topic string) *HelpTopic {
for i := range helpv {
if helpv[i].Name == topic {
return &helpv[i]
}
}
return nil
}
// AllHelpTopics returns list of all zodbtools help topics
func AllHelpTopics() []HelpTopic {
return helpv
}
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