Documentation ¶
Overview ¶
Copyright NetFoundry, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright NetFoundry, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright NetFoundry, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright NetFoundry, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func CdBucket(state *zdelib.State, registry *CommandRegistry, bucketName string) error
- func ClearConsole(_ *zdelib.State, _ *CommandRegistry, _ string) error
- func KeySuggester(state *zdelib.State, _ prompt.Document) []prompt.Suggest
- func ListCurrentBucket(state *zdelib.State, _ *CommandRegistry, args string) error
- func ListCurrentBucketAll(state *zdelib.State, _ *CommandRegistry, _ string) error
- func ListCurrentBucketWithLimits(state *zdelib.State, skip int64, limit int64) error
- func ListSuggester(_ *zdelib.State, d prompt.Document) []prompt.Suggest
- func NavBackOne(state *zdelib.State, _ *CommandRegistry, _ string) error
- func NavToRoot(state *zdelib.State, _ *CommandRegistry, _ string) error
- func PathPrompt(state *zdelib.State) string
- func PrintBucketStats(state *zdelib.State, _ *CommandRegistry, _ string) error
- func PrintCurrentCount(state *zdelib.State, _ *CommandRegistry, _ string) error
- func PrintDbStats(state *zdelib.State, _ *CommandRegistry, _ string) error
- func PrintHelp(_ *zdelib.State, registry *CommandRegistry, _ string) error
- func PrintPath(state *zdelib.State, _ *CommandRegistry, _ string) error
- func PrintUsage()
- func PrintValue(state *zdelib.State, _ *CommandRegistry, key string) error
- func PrintVersion()
- func Run(commandName, arg string) error
- type Action
- type ActionHandler
- type Command
- type CommandRegistry
- type StateCompleter
Constants ¶
const ( ArgSkip = "--skip" ArgLimit = "--limit" )
Variables ¶
var CmdBack = &Command{"back", []string{"b"}, "go back one bucket level (alias b)", nil}
var CmdCd = &Command{"cd", nil, "enter a bucket", KeySuggester}
var CmdClear = &Command{"clear", []string{"cls"}, "clear the console", nil}
var CmdCount = &Command{"count", nil, "number of keys in bucket", nil}
var CmdHelp = &Command{"help", nil, "prints help", nil}
var CmdList = &Command{"list", []string{"ls"}, "list keys", ListSuggester}
var CmdListAll = &Command{"list-all", []string{"la"}, "list all keys", nil}
var CmdPwd = &Command{"pwd", nil, "print the full path", nil}
var CmdQuit = &Command{"quit", []string{"q"}, "leave this horrible place", nil}
var CmdRoot = &Command{"root", []string{"r"}, "return to the root node (alias r)", nil}
var CmdShow = &Command{"show", nil, "print the full value of a key", KeySuggester}
var CmdStatsBucket = &Command{"stats-bucket", nil, "show stats for the current bucket", nil}
var CmdStatsDb = &Command{"stats-db", nil, "show stats for the db", nil}
var CommandName = "ziti-db-explorer"
CommandName allow usage and such to be altered to fit a hosting executable
Functions ¶
func CdBucket ¶
func CdBucket(state *zdelib.State, registry *CommandRegistry, bucketName string) error
CdBucket is an ActionHandler to `cd <bucket`. Will update the provided `state`'s location.
func ClearConsole ¶
func ClearConsole(_ *zdelib.State, _ *CommandRegistry, _ string) error
ClearConsole will output ASCII control characters that clear the console on modern terminals.
func KeySuggester ¶
func ListCurrentBucket ¶
func ListCurrentBucket(state *zdelib.State, _ *CommandRegistry, args string) error
ListCurrentBucket is an ActionHandler that will parse `args` in order to call ListCurrentBucketWithLimits.
func ListCurrentBucketAll ¶
func ListCurrentBucketAll(state *zdelib.State, _ *CommandRegistry, _ string) error
ListCurrentBucketAll is an ActionHandler that will print a table of the provided `state`'s location's keys and values. It will print all keys from first to last.
func ListCurrentBucketWithLimits ¶
ListCurrentBucketWithLimits will print a table of the provided `state`'s location's keys and values. If limit is zero or negative all values will be listed. A positive limit will only show that number of keys and values. Skip must be 0 or greater and will skip that number of keys.
func ListSuggester ¶
ListSuggester returns a list of suggestions for the `list` command
func NavBackOne ¶
func NavBackOne(state *zdelib.State, _ *CommandRegistry, _ string) error
NavBackOne is an ActionHandler that will navigate the provided `state` one bucket level back if possible.
func NavToRoot ¶
func NavToRoot(state *zdelib.State, _ *CommandRegistry, _ string) error
NavToRoot is an ActionHandler that will navigate the provided `state` to the root bucket.
func PathPrompt ¶
PathPrompt will return a string suitable to be an interactive CLI's prompt prefix.
func PrintBucketStats ¶
func PrintBucketStats(state *zdelib.State, _ *CommandRegistry, _ string) error
PrintBucketStats is an ActionHandler that will print the provided `state`'s current bucket location's stats.
func PrintCurrentCount ¶
func PrintCurrentCount(state *zdelib.State, _ *CommandRegistry, _ string) error
PrintCurrentCount is an ActionHandler that will print the key count for the provided `state`'s location.
func PrintDbStats ¶
func PrintDbStats(state *zdelib.State, _ *CommandRegistry, _ string) error
PrintDbStats is an ActionHandler that will print the bbolt database stats the current `state` has open.
func PrintPath ¶
func PrintPath(state *zdelib.State, _ *CommandRegistry, _ string) error
PrintPath is an ActionHandler that will print the provided `state`'s bucket location.
func PrintUsage ¶
func PrintUsage()
func PrintValue ¶
func PrintValue(state *zdelib.State, _ *CommandRegistry, key string) error
PrintValue will attempt to print the value from a given `key` in the current bucket location determined by `state`.
func PrintVersion ¶
func PrintVersion()
Types ¶
type Action ¶
type Action struct { prompt.Suggest Do ActionHandler IsSuggested bool }
Action is prompt.Suggest with additional values to control suggestion listing as well as to couple it to an ActionHandler.
func NewAction ¶
func NewAction(text, desc string, do ActionHandler) *Action
NewAction creates a default action with an ActionHandler that will simply print a message.
type ActionHandler ¶
type ActionHandler func(state *zdelib.State, registry *CommandRegistry, args string) error
ActionHandler is a function which can take an unparsed CLI string, parse it, and process an action
type Command ¶
type Command struct { Text string Aliases []string Description string Suggester func(state *zdelib.State, d prompt.Document) []prompt.Suggest }
Command represents a string (`Text`) an aliases (`Aliases`) that have a specific description and suggestion result set.
type CommandRegistry ¶
type CommandRegistry struct { CommandTextToCommand map[string]*Command CommandTextToAction map[string]*Action CommandTexts []string }
CommandRegistry provides efficient lookup of Action and Command entities by command text and aliases for suggestions and action invocation.
func NewCommandRegistry ¶
func NewCommandRegistry() *CommandRegistry
NewCommandRegistry returns an empty registry.
func (*CommandRegistry) Add ¶
func (registry *CommandRegistry) Add(cmd *Command, handler ActionHandler)
Add adds a new string cmdText with any number of string command aliases. `desc` will be displayed to provide hints on what a command does. The provided ActionHandler will be invoked when cmdText or aliases are matched.
func (*CommandRegistry) AddUnlisted ¶
func (registry *CommandRegistry) AddUnlisted(cmd *Command, handler ActionHandler)
AddUnlisted is the same as Add, but it will not show up in suggestions.
func (*CommandRegistry) GetCommand ¶
func (registry *CommandRegistry) GetCommand(cmdText string) *Command
GetCommand returns the command with text or aliases that match cmdText. If not found, returns nil
type StateCompleter ¶
type StateCompleter struct { State *zdelib.State Registry *CommandRegistry }
StateCompleter is used to package a prompt.Completer with location zdelib.State as well as an CommandRegistry. This allows a prompt.Completer to provide current bucket location suggestions (i.e. key values completing) as well as provide command suggestions.
func (*StateCompleter) Complete ¶
func (completer *StateCompleter) Complete(d prompt.Document) []prompt.Suggest
Complete implements the signature required of a prompt.Completer. It parses the current prompt.Document to provide suggestions and tab-completion for bucket keys as well as Action's from the provided CommandRegistry.
func (*StateCompleter) FirstWord ¶
func (completer *StateCompleter) FirstWord(d prompt.Document) string
FirstWord returns the first word of the current input or empty string