cmd

package
v0.0.0-...-dee8dd0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2017 License: ISC Imports: 19 Imported by: 0

Documentation

Overview

Package cmd provides for the interpretation of commands from a user interface, either email or rpc.

See command.go for information on the available commands and instructions on how to implement more commands.

Index

Constants

View Source
const DefaultSendAck = true

DefaultSendAck is set to true, which means that new addresses by default return ack messages.

Variables

View Source
var (
	// ErrInvalidString is returned when a string is expected but
	// the given input does not match the string pattern.
	ErrInvalidString = errors.New("Invalid string pattern. Should be delimited by \" ")

	// ErrInvalidBoolean is returned when a boolean is expected but
	// the given input does not match boolean type.
	ErrInvalidBoolean = errors.New("Boolean should be 'true' or 'false'")

	// ErrInvalidSymbol is returned when a boolean is expected but
	// the given input does not match boolean type.
	ErrInvalidSymbol = errors.New("Boolean should be 'true' or 'false'")

	// ErrInvalidType is returned when the type provided cannot be read.
	ErrInvalidType = errors.New("Cannot read the given type.")

	// ErrInvalidRPCRequest is returned when an rpc request is invalid.
	ErrInvalidRPCRequest = errors.New("Invalid rpc request.")
)
View Source
var Commands = []string{
	"deletemessages",
	"getmessages",
	"help",
	"listaddresses",
	"newaddress",
	"sendmessage",
}

Commands is the list of commands.

View Source
var ErrServerStopped = errors.New("Server is not running.")

ErrServerStopped is returned when an rpc call is made and the server isn't running.

View Source
var Unimplemented = []string{
	"deletemessages",
	"getmessages",
	"listaddresses",
	"newaddress",
	"sendmessage",
}

Unimplemented is the list of unimplemented commands.

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.

func EmailCommand

func EmailCommand(u User, from, agent, name string, params []string) *email.Bmail

EmailCommand manages a request sent via the email interface.

func PublicToRPC

func PublicToRPC(ip PublicID) *rpc.BitmessageIdentity

PublicToRPC converts an identity.Public to a BitmessageIdentity

func RPCCommand

func RPCCommand(u User, request *pb.BMRPCRequest) (*pb.BMRPCReply, error)

RPCCommand manages a request sent via an rpc interface.

func ReadPattern

func ReadPattern(params []string, elements ...interface{}) error

ReadPattern attempts to return a type corresponding to the given pattern which is read from the given string.

func SubjectRe

func SubjectRe(cmd string, p []string) string

SubjectRe creates the subject line of an email reply.

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output client logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.

func ØMQServer

func ØMQServer()

ØMQServer sets up the ØMQ Server

Types

type Command

type Command interface {
	Execute(User) (Response, error)
	RPC() (*rpc.BMRPCRequest, error)
}

Command is the type created from the input through the user interface, either via email or via rpc.

func BuildCommand

func BuildCommand(r *pb.BMRPCRequest) (Command, error)

BuildCommand translates an rpc request into a Command type.

func ReadCommand

func ReadCommand(name string, param []string) (Command, error)

ReadCommand attempts to take a command name and list of parameters and translates it into a Command type.

type ErrInvalidNumberOfParameters

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

ErrInvalidNumberOfParameters is an error representing an invalid number of parameters.

func (*ErrInvalidNumberOfParameters) Error

func (err *ErrInvalidNumberOfParameters) Error() string

type ErrUnimplemented

type ErrUnimplemented struct {
	Command string
}

ErrUnimplemented implements the error interface and is returned when a user calls an unimplemented command.

func (*ErrUnimplemented) Error

func (err *ErrUnimplemented) Error() string

Error constructs the error message as a string.

type ErrUnknownCommand

type ErrUnknownCommand struct {
	Command string
}

ErrUnknownCommand implements the error interface and is returned when a user calls an unknown command.

func (*ErrUnknownCommand) Error

func (err *ErrUnknownCommand) Error() string

Error constructs the error message as a string.

type ErrUnrecognizedPattern

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

ErrUnrecognizedPattern implements the error interface and and is returned when the user provides an unrecognized pattern.

func (*ErrUnrecognizedPattern) Error

func (err *ErrUnrecognizedPattern) Error() string

Error constructs the error message as a string.

type Key

type Key uint32

Key is an element of the patterns used to define command parameters for email requests.

const (
	// KeyRepeated is written +, represents any positive number of repetitions
	// of the previous pattern element.
	KeyRepeated Key = Key(0)

	// KeyRepeatedNull is written * represents any number of repetitions of
	// the previous pattern element, including zero.
	KeyRepeatedNull Key = Key(1)

	// KeyBoolean represents a boolean value.
	KeyBoolean Key = Key(2)

	// KeyNatural represents a natural number value.
	KeyNatural Key = Key(3)

	// KeyString represents a string value.
	KeyString Key = Key(4)

	// KeySymbol represents a symbol value.
	KeySymbol Key = Key(5)
)

type Pattern

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

Pattern represents a valid way of interpreting a command with a set of parameters.

type PublicID

type PublicID struct {
	ID    identity.Public
	Label string
}

PublicID is a public identity with a name.

type RPCClient

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

func GRPCClient

func GRPCClient(cfg *bmrpc.ClientConfig) (*RPCClient, error)

GRPCClient creates the GRPC client.

func (*RPCClient) Request

func (r *RPCClient) Request(in *pb.BMRPCRequest) (*pb.BMRPCReply, error)

type RPCServer

type RPCServer struct {
	rpc.Server
	// contains filtered or unexported fields
}

RPCServer is a server that can listen and execute rpc commands.

func GRPCServer

func GRPCServer(u User, cfg *rpc.Config) (*RPCServer, error)

GRPCServer creates a grpc GRPC server.

func (*RPCServer) BMAgentRequest

func (s *RPCServer) BMAgentRequest(ctx context.Context, req *pb.BMRPCRequest) (*pb.BMRPCReply, error)

BMAgentRequest returns the feature at the given point.

type Response

type Response interface {
	String() string
	RPC() *rpc.BMRPCReply
}

Response is the type returned by a command. It can be delivered to the user as a json object or as an email.

func ErrorResponse

func ErrorResponse(err error) Response

ErrorResponse creates an errorResponse object.

type User

type User interface {
	NewAddress(tag string, sendAck bool) PublicID
	ListAddresses() []PublicID
}

User represents an implementation of lower-level functions to be performed as commands are executed.

Directories

Path Synopsis
Package rpc is a generated protocol buffer package.
Package rpc is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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