cli

package
v0.40.4 Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: Apache-2.0 Imports: 31 Imported by: 2

Documentation

Overview

Package cli provides utilities for the dolt command line.

cli provides:

  • the interface for creating and managing hierarchical dolt commands. These typically have command lines that look like: app command [<options>] app command subcommand [<options>] app command subcommand1 subcommand2 [<options>] etc.

  • Command help and usage printing

  • The interface for writing output to the user

  • Argument parsing utility methods

Index

Constants

View Source
const (
	AllowEmptyFlag   = "allow-empty"
	DateParam        = "date"
	CommitMessageArg = "message"
	AuthorParam      = "author"
	ForceFlag        = "force"
	DryRunFlag       = "dry-run"
	SetUpstreamFlag  = "set-upstream"
	AllFlag          = "all"
	HardResetParam   = "hard"
	SoftResetParam   = "soft"
	CheckoutCoBranch = "b"
	NoFFParam        = "no-ff"
	SquashParam      = "squash"
	AbortParam       = "abort"
	CopyFlag         = "copy"
	MoveFlag         = "move"
	DeleteFlag       = "delete"
	DeleteForceFlag  = "D"
)
View Source
const (
	SyncBackupId        = "sync"
	RestoreBackupId     = "restore"
	AddBackupId         = "add"
	RemoveBackupId      = "remove"
	RemoveBackupShortId = "rm"
)
View Source
const VerboseFlag = "verbose"

Variables

View Source
var CliErr = color.Error
View Source
var CliFormat = docFormat{"<", ">", "<b>", "</b>"}

Shell help output format

View Source
var CliOut = colorOutput
View Source
var ErrEmptyDefTuple = errors.New("empty definition tuple")
View Source
var ExecuteWithStdioRestored func(userFunc func())
View Source
var InStream io.ReadCloser = os.Stdin
View Source
var MarkdownFormat = docFormat{"`<", ">`", "`", "`"}

mdx format

View Source
var OutStream io.WriteCloser = os.Stdout
View Source
var SupportedLayouts = []string{
	"2006/01/02",
	"2006/01/02T15:04:05",
	"2006/01/02T15:04:05Z07:00",

	"2006.01.02",
	"2006.01.02T15:04:05",
	"2006.01.02T15:04:05Z07:00",

	"2006-01-02",
	"2006-01-02T15:04:05",
	"2006-01-02T15:04:05Z07:00",
}

we are more permissive than what is documented.

View Source
var SynopsisMarkdownFormat = docFormat{"<", ">", "`", "`"}

Synopsis is an mdx format, but already inside a code block

Functions

func CheckEnvIsValid

func CheckEnvIsValid(dEnv *env.DoltEnv) bool

CheckEnvIsValid validates that a DoltEnv has been initialized properly and no errors occur during load, and prints error messages to the user if there are issues with the environment or if errors were encountered while loading it.

func CheckUserNameAndEmail

func CheckUserNameAndEmail(dEnv *env.DoltEnv) bool

CheckUserNameAndEmail returns true if the user name and email are set for this environment, or prints an error and returns false if not.

func CloseOutput

func CloseOutput()

func ColumnNameFromColumnError

func ColumnNameFromColumnError(err error) string

func CreateAddArgParser

func CreateAddArgParser() *argparser.ArgParser

func CreateBackupArgParser

func CreateBackupArgParser() *argparser.ArgParser

func CreateBranchArgParser

func CreateBranchArgParser() *argparser.ArgParser

func CreateCheckoutArgParser

func CreateCheckoutArgParser() *argparser.ArgParser

func CreateCleanArgParser

func CreateCleanArgParser() *argparser.ArgParser

func CreateCommitArgParser

func CreateCommitArgParser() *argparser.ArgParser

Creates the argparser shared dolt commit cli and DOLT_COMMIT.

func CreateFetchArgParser

func CreateFetchArgParser() *argparser.ArgParser

func CreateMergeArgParser

func CreateMergeArgParser() *argparser.ArgParser

func CreatePullArgParser

func CreatePullArgParser() *argparser.ArgParser

func CreatePushArgParser

func CreatePushArgParser() *argparser.ArgParser

func CreateResetArgParser

func CreateResetArgParser() *argparser.ArgParser

func CreateRevertArgParser

func CreateRevertArgParser() *argparser.ArgParser

func DeleteAndPrint

func DeleteAndPrint(prevMsgLen int, msg string) int

DeleteAndPrint prints a new message and deletes the old one given the previous messages length. It returns the length of the printed message that should be passed as prevMsgLen on the next call of DeleteAndPrint.

DeleteAndPrint does not work for multiline messages.

func HelpAndUsagePrinters

func HelpAndUsagePrinters(cmdDoc CommandDocumentation) (UsagePrinter, UsagePrinter)

func InitIO

func InitIO() (restoreIO func())

func IsColumnError

func IsColumnError(err error) bool

func OptionsUsage

func OptionsUsage(ap *argparser.ArgParser, indent string, lineLen int) string

func ParseArgs

func ParseArgs(ap *argparser.ArgParser, args []string, usagePrinter UsagePrinter) (*argparser.ArgParseResults, error)

ParseArgs is used for Dolt SQL functions that are run on the server and should not exit

func ParseArgsOrDie

func ParseArgsOrDie(ap *argparser.ArgParser, args []string, usagePrinter UsagePrinter) *argparser.ArgParseResults

ParseArgsOrDie is used for CLI command that should exit after erroring.

func ParseAuthor

func ParseAuthor(authorStr string) (string, string, error)

Parses the author flag for the commit method.

func ParseDate

func ParseDate(dateStr string) (time.Time, error)

Parses a date string. Used by multiple commands.

func ParseKeyValues

func ParseKeyValues(ctx context.Context, vrw types.ValueReadWriter, sch schema.Schema, args []string) ([]types.Value, error)

func Print

func Print(a ...interface{})

func PrintErr

func PrintErr(a ...interface{})

func PrintErrf

func PrintErrf(format string, a ...interface{})

func PrintErrln

func PrintErrln(a ...interface{})

func PrintHelpText

func PrintHelpText(commandStr, shortDesc, longDesc string, synopsis []string, parser *argparser.ArgParser)

func PrintUsage

func PrintUsage(commandStr string, synopsis []string, parser *argparser.ArgParser)

func Printf

func Printf(format string, a ...interface{})

func Println

func Println(a ...interface{})

func SetIOStreams

func SetIOStreams(inStream io.ReadCloser, outStream io.WriteCloser)

func ToIndentedParagraph

func ToIndentedParagraph(inStr, indent string, lineLen int) string

Types

type ColumnError

type ColumnError struct {
	// contains filtered or unexported fields
}

func (ColumnError) Error

func (ce ColumnError) Error() string

type Command

type Command interface {
	// Name returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
	Name() string
	// Description returns a description of the command
	Description() string
	// Exec executes the command
	Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int
	// CreateMarkdown creates a markdown file containing the helptext for the command at the given path
	CreateMarkdown(writer io.Writer, commandStr string) error
	// ArgParser returns the arg parser for this command
	ArgParser() *argparser.ArgParser
}

Command is the interface which defines a Dolt cli command

type CommandDocumentation

type CommandDocumentation struct {
	// The command/sub-command string passed to a command by the caller
	CommandStr string
	// The short description of the command
	ShortDesc string
	// The long description of the command
	LongDesc string
	// The synopsis, an array of strings showing how to use the command
	Synopsis []string
	// A structure that
	ArgParser *argparser.ArgParser
}

A struct that represents all the data structures required to create the documentation for a command.

func GetCommandDocumentation

func GetCommandDocumentation(commandStr string, cmdDoc CommandDocumentationContent, argParser *argparser.ArgParser) CommandDocumentation

Creates a CommandDocumentation given command string, arg parser, and a CommandDocumentationContent

func (CommandDocumentation) CmdDocToMd

func (cmdDoc CommandDocumentation) CmdDocToMd() (string, error)

func (CommandDocumentation) GetLongDesc

func (cmdDoc CommandDocumentation) GetLongDesc(format docFormat) (string, error)

Returns the LongDesc field of the receiver CommandDocumentation with the passed DocFormat injected into the template

func (CommandDocumentation) GetShortDesc

func (cmdDoc CommandDocumentation) GetShortDesc() string

Returns the ShortDesc field of the receiver CommandDocumentation with the passed DocFormat injected into the template

func (CommandDocumentation) GetSynopsis

func (cmdDoc CommandDocumentation) GetSynopsis(format docFormat) ([]string, error)

Returns the synopsis iterating over each element and injecting the supplied DocFormat

type CommandDocumentationContent

type CommandDocumentationContent struct {
	ShortDesc string
	LongDesc  string
	Synopsis  []string
}

This type is to store the content of a documented command, elsewhere we can transform this struct into other structs that are used to generate documentation at the command line and in markdown files.

type EphemeralPrinter

type EphemeralPrinter struct {
	// contains filtered or unexported fields
}

EphemeralPrinter is tool than you can use to print temporary line(s) to the console. Each time Display is called, the output is reset, and you can begin writing anew.

func NewEphemeralPrinter

func NewEphemeralPrinter() *EphemeralPrinter

NewEphemeralPrinter creates a new EphemeralPrinter.

func (*EphemeralPrinter) Display

func (e *EphemeralPrinter) Display()

Display clears the previous output and displays the new text.

func (*EphemeralPrinter) Printf

func (e *EphemeralPrinter) Printf(format string, a ...interface{})

Printf formats and prints a string to the printer. If no newline character is provided, one will be added to ensure that the output can be cleared in the future. You can print multiple lines.

type EventMonitoredCommand

type EventMonitoredCommand interface {
	// EventType returns the type of the event to log
	EventType() eventsapi.ClientEventType
}

EventMonitoredCommand is an optional interface that can be overridden in order to generate an event which is sent to the metrics system when the command is run

type FormatGatedCommand

type FormatGatedCommand interface {
	Command

	GatedForNBF(nbf *types.NomsBinFormat) bool
}

type HiddenCommand

type HiddenCommand interface {
	// Hidden should return true if this command should be hidden from the help text
	Hidden() bool
}

HiddenCommand is an optional interface that can be overridden so that a command is hidden from the help text

type RepoNotRequiredCommand

type RepoNotRequiredCommand interface {
	// RequiresRepo should return false if this interface is implemented, and the command does not have the requirement
	// that it be run from within a data repository directory
	RequiresRepo() bool
}

RepoNotRequiredCommand is an optional interface that commands can implement if the command can be run without the current directory being a valid Dolt data repository. Any commands not implementing this interface are assumed to require that they be run from a directory containing a Dolt data repository.

type SignalCommand

type SignalCommand interface {
	Command

	// InstallsSignalHandlers returns whether this command manages its own signal handlers for interruption / termination.
	InstallsSignalHandlers() bool
}

SignalCommand is an extension of Command that allows commands to install their own signal handlers, rather than use the global one (which cancels the global context).

type SubCommandHandler

type SubCommandHandler struct {

	// Unspecified ONLY applies when no other command has been given. This is different from how a default command would
	// function, as a command that doesn't exist for this sub handler will result in an error.
	Unspecified Command
	Subcommands []Command
	// contains filtered or unexported fields
}

SubCommandHandler is a command implementation which holds subcommands which can be called

func NewHiddenSubCommandHandler

func NewHiddenSubCommandHandler(name, description string, subcommands []Command) SubCommandHandler

NewHiddenSubCommandHandler returns a new SubCommandHandler instance that is hidden from display

func NewSubCommandHandler

func NewSubCommandHandler(name, description string, subcommands []Command) SubCommandHandler

NewSubCommandHandler returns a new SubCommandHandler instance

func NewSubCommandHandlerWithUnspecified

func NewSubCommandHandlerWithUnspecified(name, description string, hidden bool, unspecified Command, subcommands []Command) SubCommandHandler

NewSubCommandHandlerWithUnspecified returns a new SubCommandHandler that will invoke the unspecified command ONLY if no direct command is given.

func (SubCommandHandler) ArgParser

func (hc SubCommandHandler) ArgParser() *argparser.ArgParser

func (SubCommandHandler) CreateMarkdown

func (hc SubCommandHandler) CreateMarkdown(_ io.Writer, _ string) error

func (SubCommandHandler) Description

func (hc SubCommandHandler) Description() string

func (SubCommandHandler) Exec

func (hc SubCommandHandler) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int

func (SubCommandHandler) Hidden

func (hc SubCommandHandler) Hidden() bool

func (SubCommandHandler) Name

func (hc SubCommandHandler) Name() string

func (SubCommandHandler) RequiresRepo

func (hc SubCommandHandler) RequiresRepo() bool

type UsagePrinter

type UsagePrinter func()

Jump to

Keyboard shortcuts

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