metacmd

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2018 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

SectionOrder is the order of sections to display via Listing.

Functions

func Listing

func Listing(w io.Writer)

Listing writes the formatted command listing to w, separated into different sections for all known commands.

Types

type Cmd

type Cmd struct {
	Section Section
	Name    string
	Desc    string
	Min     int
	Aliases map[string]string
	Process func(*Params) error
}

Cmd is a command implementation.

type ExecType

type ExecType int

ExecType represents the type of execution requested.

const (
	// ExecNone indicates no execution.
	ExecNone ExecType = iota

	// ExecOnly indicates plain execution only (\g).
	ExecOnly

	// ExecPipe indicates execution and piping results (\g |file)
	ExecPipe

	// ExecSet indicates execution and setting the resulting columns as
	// variables (\gset).
	ExecSet

	// ExecExec indicates execution and executing the resulting rows (\gexec).
	ExecExec
)

type Handler

type Handler interface {
	// IO handles the handler's IO.
	IO() rline.IO

	// User returns the current user.
	User() *user.User

	// URL returns the current database URL.
	URL() *dburl.URL

	// DB returns the current database connection.
	DB() drivers.DB

	// Last returns the last executed query.
	Last() string

	// Buf returns the current query buffer.
	Buf() *stmt.Stmt

	// Reset resets the last and current query buffer.
	Reset([]rune)

	// Open opens a database connection.
	Open(...string) error

	// Close closes the current database connection.
	Close() error

	// ChangePassword changes the password for a user.
	ChangePassword(string) (string, error)

	// ReadVar reads a variable of a specified type.
	ReadVar(string, string) (string, error)

	// Include includes a file.
	Include(string, bool) error

	// Begin begins a transaction.
	Begin() error

	// Commit commits the current transaction.
	Commit() error

	// Rollback aborts the current transaction.
	Rollback() error

	// Highlight highlights the statement.
	Highlight(io.Writer, string) error
}

Handler is the shared interface for a command handler.

type Metacmd

type Metacmd uint

Metacmd represents a command and associated meta information about it.

const (
	// None is an empty command.
	None Metacmd = iota

	// Question is question meta command (\?)
	Question

	// Quit is the quit meta command (\?).
	Quit

	// Copyright is the copyright meta command (\copyright).
	Copyright

	// Connect is the connect meta command (\c).
	Connect

	// Disconnect is the disconnect meta command (\Z).
	Disconnect

	// Password is the change password meta command (\password).
	Password

	// ConnInfo is the connection info meta command (\conninfo).
	ConnInfo

	// Drivers is the driver info meta command (\drivers).
	Drivers

	// Describe is the describe meta command (\d and variants).
	Describe

	// Exec is the execute meta command (\g and variants).
	Exec

	// Edit is the edit query buffer meta command (\e).
	Edit

	// Print is the print query buffer meta command (\p).
	Print

	// Reset is the reset query buffer meta command (\r).
	Reset

	// Echo is the echo meta command (\echo).
	Echo

	// Write is the write meta command (\w).
	Write

	// ChangeDir is the system change directory meta command (\cd).
	ChangeDir

	// SetEnv is the system set environment variable meta command (\setenv).
	SetEnv

	// ShellExec is the system shell exec meta command (\!).
	ShellExec

	// Include is the system include file meta command (\i and variants).
	Include

	// Begin is the transaction begin meta command (\begin).
	Begin

	// Commit is the transaction commit meta command (\commit).
	Commit

	// Rollback is the transaction rollback (abort) meta command (\rollback).
	Rollback

	// Prompt is the variable prompt meta command (\prompt).
	Prompt

	// Set is the variable set meta command (\set).
	Set

	// Unset is the variable unset meta command (\unset).
	Unset
)

Command types.

type Params added in v0.5.0

type Params struct {
	// H is the handler.
	H Handler

	// N is the name of the command.
	N string

	// P are the passed parameters.
	P []string

	// R is the resulting state of the command execution.
	R Res
}

Params wraps command parameters.

func (*Params) A added in v0.5.0

func (p *Params) A() []string

A returns all remaining, unprocessed parameters, incrementing p.R.processed appropriately.

func (*Params) G added in v0.5.0

func (p *Params) G() string

G returns the next parameter, increasing p.R.Processed by 1.

func (*Params) V added in v0.5.0

func (p *Params) V(d string) string

V returns the next parameter only if it is prefixed with a "-", increasing p.R.Processed when it is, otherwise returning d.

type Res

type Res struct {
	// Quit instructs the handling code to quit.
	Quit bool

	// Exec informs the handling code of the type of execution.
	Exec ExecType

	// ExecParam is an accompanying parameter for execution. For ExecPipe, it
	// will be the name of a file. For ExecSet it will be the variable prefix.
	ExecParam string

	// Processed informs the handling code how many parameters went
	// unprocessed. A value of 0 means that no parameters were processed.
	Processed int
}

Res is the result of a meta command execution.

type Runner

type Runner interface {
	Run(Handler) (Res, error)
}

Runner is a runner interface type.

func Decode

func Decode(name string, params []string) (Runner, error)

Decode converts a command name (or alias) into a Runner.

type RunnerFunc

type RunnerFunc func(Handler) (Res, error)

RunnerFunc is a type wrapper for a single func satisfying Runner.Run.

func (RunnerFunc) Run

func (f RunnerFunc) Run(h Handler) (Res, error)

Run satisfies the Runner interface.

type Section

type Section string

Section is a meta command section.

const (
	SectionGeneral         Section = "General"
	SectionHelp            Section = "Help"
	SectionQueryBuffer     Section = "Query Buffer"
	SectionTransaction     Section = "Transaction"
	SectionInputOutput     Section = "Input/Output"
	SectionInformational   Section = "Informational"
	SectionFormatting      Section = "Formatting"
	SectionConnection      Section = "Connection"
	SectionOperatingSystem Section = "Operating System"
	SectionVariables       Section = "Variables"
)

Meta command section types.

func (Section) String

func (s Section) String() string

String satisfies stringer.

Jump to

Keyboard shortcuts

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