Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
62dc2806
Commit
62dc2806
authored
Apr 25, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
e2266200
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
95 additions
and
42 deletions
+95
-42
go/neo/cmd/neo/neo.go
go/neo/cmd/neo/neo.go
+35
-8
go/neo/command.go
go/neo/command.go
+29
-0
go/zodb/cmd/zodb/zodb.go
go/zodb/cmd/zodb/zodb.go
+5
-5
go/zodb/zodbtools/command.go
go/zodb/zodbtools/command.go
+11
-13
go/zodb/zodbtools/help.go
go/zodb/zodbtools/help.go
+15
-16
No files found.
go/neo/cmd/neo/neo.go
View file @
62dc2806
...
...
@@ -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
)
}
...
...
go/neo/command.go
0 → 100644
View file @
62dc2806
// 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
}
go/zodb/cmd/zodb/zodb.go
View file @
62dc2806
...
...
@@ -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."
)
...
...
go/zodb/zodbtools/command.go
View file @
62dc2806
...
...
@@ -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
// Lookup
Command
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
},
}
go/zodb/zodbtools/help.go
View file @
62dc2806
...
...
@@ -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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment