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
- Variables
- func CheckEnvIsValid(dEnv *env.DoltEnv) bool
- func CheckUserNameAndEmail(dEnv *env.DoltEnv) bool
- func CloseOutput()
- func ColumnNameFromColumnError(err error) string
- func CreateAddArgParser() *argparser.ArgParser
- func CreateBackupArgParser() *argparser.ArgParser
- func CreateBranchArgParser() *argparser.ArgParser
- func CreateCheckoutArgParser() *argparser.ArgParser
- func CreateCleanArgParser() *argparser.ArgParser
- func CreateCommitArgParser() *argparser.ArgParser
- func CreateFetchArgParser() *argparser.ArgParser
- func CreateMergeArgParser() *argparser.ArgParser
- func CreatePullArgParser() *argparser.ArgParser
- func CreatePushArgParser() *argparser.ArgParser
- func CreateResetArgParser() *argparser.ArgParser
- func CreateRevertArgParser() *argparser.ArgParser
- func DeleteAndPrint(prevMsgLen int, msg string) int
- func HelpAndUsagePrinters(cmdDoc CommandDocumentation) (UsagePrinter, UsagePrinter)
- func InitIO() (restoreIO func())
- func IsColumnError(err error) bool
- func OptionsUsage(ap *argparser.ArgParser, indent string, lineLen int) string
- func ParseArgs(ap *argparser.ArgParser, args []string, usagePrinter UsagePrinter) (*argparser.ArgParseResults, error)
- func ParseArgsOrDie(ap *argparser.ArgParser, args []string, usagePrinter UsagePrinter) *argparser.ArgParseResults
- func ParseAuthor(authorStr string) (string, string, error)
- func ParseDate(dateStr string) (time.Time, error)
- func ParseKeyValues(ctx context.Context, vrw types.ValueReadWriter, sch schema.Schema, ...) ([]types.Value, error)
- func Print(a ...interface{})
- func PrintErr(a ...interface{})
- func PrintErrf(format string, a ...interface{})
- func PrintErrln(a ...interface{})
- func PrintHelpText(commandStr, shortDesc, longDesc string, synopsis []string, ...)
- func PrintUsage(commandStr string, synopsis []string, parser *argparser.ArgParser)
- func Printf(format string, a ...interface{})
- func Println(a ...interface{})
- func SetIOStreams(inStream io.ReadCloser, outStream io.WriteCloser)
- func ToIndentedParagraph(inStr, indent string, lineLen int) string
- type ColumnError
- type Command
- type CommandDocumentation
- type CommandDocumentationContent
- type EphemeralPrinter
- type EventMonitoredCommand
- type FormatGatedCommand
- type HiddenCommand
- type RepoNotRequiredCommand
- type SignalCommand
- type SubCommandHandler
- func NewHiddenSubCommandHandler(name, description string, subcommands []Command) SubCommandHandler
- func NewSubCommandHandler(name, description string, subcommands []Command) SubCommandHandler
- func NewSubCommandHandlerWithUnspecified(name, description string, hidden bool, unspecified Command, ...) SubCommandHandler
- func (hc SubCommandHandler) ArgParser() *argparser.ArgParser
- func (hc SubCommandHandler) CreateMarkdown(_ io.Writer, _ string) error
- func (hc SubCommandHandler) Description() string
- func (hc SubCommandHandler) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv) int
- func (hc SubCommandHandler) Hidden() bool
- func (hc SubCommandHandler) Name() string
- func (hc SubCommandHandler) RequiresRepo() bool
- type UsagePrinter
Constants ¶
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" )
const ( SyncBackupId = "sync" RestoreBackupId = "restore" AddBackupId = "add" RemoveBackupId = "remove" RemoveBackupShortId = "rm" )
const VerboseFlag = "verbose"
Variables ¶
var CliErr = color.Error
var CliFormat = docFormat{"<", ">", "<b>", "</b>"}
Shell help output format
var CliOut = colorOutput
var ErrEmptyDefTuple = errors.New("empty definition tuple")
var ExecuteWithStdioRestored func(userFunc func())
var InStream io.ReadCloser = os.Stdin
var MarkdownFormat = docFormat{"`<", ">`", "`", "`"}
mdx format
var OutStream io.WriteCloser = os.Stdout
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.
var SynopsisMarkdownFormat = docFormat{"<", ">", "`", "`"}
Synopsis is an mdx format, but already inside a code block
Functions ¶
func CheckEnvIsValid ¶
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 ¶
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 CreateAddArgParser ¶
func CreateBackupArgParser ¶
func CreateBranchArgParser ¶
func CreateCheckoutArgParser ¶
func CreateCleanArgParser ¶
func CreateCommitArgParser ¶
Creates the argparser shared dolt commit cli and DOLT_COMMIT.
func CreateFetchArgParser ¶
func CreateMergeArgParser ¶
func CreatePullArgParser ¶
func CreatePushArgParser ¶
func CreateResetArgParser ¶
func CreateRevertArgParser ¶
func DeleteAndPrint ¶
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 IsColumnError ¶
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 ¶
Parses the author flag for the commit method.
func ParseKeyValues ¶
func PrintErrln ¶
func PrintErrln(a ...interface{})
func PrintHelpText ¶
func PrintUsage ¶
func SetIOStreams ¶
func SetIOStreams(inStream io.ReadCloser, outStream io.WriteCloser)
func ToIndentedParagraph ¶
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 ¶
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) 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()