zdecli

package
v1.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2023 License: Apache-2.0 Imports: 13 Imported by: 1

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

View Source
const (
	ArgSkip  = "--skip"
	ArgLimit = "--limit"
)

Variables

View Source
var CmdBack = &Command{"back", []string{"b"}, "go back one bucket level (alias b)", nil}
View Source
var CmdCd = &Command{"cd", nil, "enter a bucket", KeySuggester}
View Source
var CmdClear = &Command{"clear", []string{"cls"}, "clear the console", nil}
View Source
var CmdCount = &Command{"count", nil, "number of keys in bucket", nil}
View Source
var CmdHelp = &Command{"help", nil, "prints help", nil}
View Source
var CmdList = &Command{"list", []string{"ls"}, "list keys", ListSuggester}
View Source
var CmdListAll = &Command{"list-all", []string{"la"}, "list all keys", nil}
View Source
var CmdPwd = &Command{"pwd", nil, "print the full path", nil}
View Source
var CmdQuit = &Command{"quit", []string{"q"}, "leave this horrible place", nil}
View Source
var CmdRoot = &Command{"root", []string{"r"}, "return to the root node (alias r)", nil}
View Source
var CmdShow = &Command{"show", nil, "print the full value of a key", KeySuggester}
View Source
var CmdStatsBucket = &Command{"stats-bucket", nil, "show stats for the current bucket", nil}
View Source
var CmdStatsDb = &Command{"stats-db", nil, "show stats for the db", nil}
View Source
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 KeySuggester(state *zdelib.State, _ prompt.Document) []prompt.Suggest

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

func ListCurrentBucketWithLimits(state *zdelib.State, skip int64, limit int64) error

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

func ListSuggester(_ *zdelib.State, d prompt.Document) []prompt.Suggest

ListSuggester returns a list of suggestions for the `list` command

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(state *zdelib.State, _ *CommandRegistry, _ string) error

NavToRoot is an ActionHandler that will navigate the provided `state` to the root bucket.

func PathPrompt

func PathPrompt(state *zdelib.State) string

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 PrintHelp

func PrintHelp(_ *zdelib.State, registry *CommandRegistry, _ string) error

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()

func Run

func Run(commandName, arg string) error

Run is called by main() and is provided so that ziti-db-explorer can be embedded in other CLIs. commandName should be the full command to run ziti-db-explorer (e.g. ziti db explore).

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.

func (*Command) Matches

func (command *Command) Matches(text string) bool

Matches returns true if the provided text match a command's text or aliases

func (*Command) Suggest

func (command *Command) Suggest(state *zdelib.State, d prompt.Document) []prompt.Suggest

Suggest will return the prompt suggestions for the command if command.Suggester is defined. Otherwise, returns nil.

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL