command

package
v0.0.0-...-42bc289 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2016 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ALIAS_CMD      = "ALIAS"
	CONNECT_CMD    = "CONNECT"
	DISCONNECT_CMD = "DISCONNECT"
	EXIT_CMD       = "EXIT"
	QUIT_CMD       = "QUIT"
	HELP_CMD       = "HELP"
	VERSION_CMD    = "VERSION"
	COPYRIGHT_CMD  = "COPYRIGHT"
	SET_CMD        = "SET"
	PUSH_CMD       = "PUSH"
	POP_CMD        = "POP"
	UNSET_CMD      = "UNSET"
	ECHO_CMD       = "ECHO"
	UNALIAS_CMD    = "UNALIAS"
	SOURCE_CMD     = "SOURCE"
)
View Source
const (
	SHELL_VERSION = "1.0"

	MAX_ARGS    = math.MaxInt16
	MAX_ALIASES = math.MaxInt16
	MAX_VARS    = math.MaxInt16
)

Variables

View Source
var (
	//Used to manage connections
	SERVICE_URL = ""
	//Used to disconnect from the endpoint
	DISCONNECT = false
	//Used to quit shell
	EXIT = false
	//Used to check for files
	FILE_INPUT = false
	//Total no. of commands
	MAX_COMMANDS = len(COMMAND_LIST)
)
View Source
var (
	QueryParam map[string]*Stack = map[string]*Stack{}
	NamedParam map[string]*Stack = map[string]*Stack{}
	UserDefSV  map[string]*Stack = map[string]*Stack{}
	PreDefSV   map[string]*Stack = map[string]*Stack{
		"querycreds": Stack_Helper(),
		"limit":      Stack_Helper(),
		"histfile":   Stack_Helper(),
		"histsize":   Stack_Helper(),
		"autoconfig": Stack_Helper(),
		"state":      Stack_Helper(),
	}
)
View Source
var AliasCommand = map[string]string{
	"serverversion": "select version()",
}

Used to define aliases

View Source
var COMMAND_LIST = map[string]ShellCommand{

	"\\connect":    &Connect{},
	"\\disconnect": &Disconnect{},
	"\\exit":       &Exit{},
	"\\quit":       &Exit{},

	"\\help":      &Help{},
	"\\version":   &Version{},
	"\\copyright": &Copyright{},

	"\\set":     &Set{},
	"\\push":    &Push{},
	"\\pop":     &Pop{},
	"\\unset":   &Unset{},
	"\\echo":    &Echo{},
	"\\alias":   &Alias{},
	"\\unalias": &Unalias{},
}

Command registry : List of Shell Commands supported by cbq

Define a common writer to output the responses to.

Functions

func HandleError

func HandleError(err int, msg string) errors.Error

func PopValue_Helper

func PopValue_Helper(unset bool, param map[string]*Stack, vble string) (err_code int, err_str string)

Helper function to pop or unset a value in a stack.

func Popparam_Helper

func Popparam_Helper(param map[string]*Stack, isrestp bool, isnamep bool) (int, string)

Pop the top value of the parameter stack.

This is used by the \POP command with no arguments.

func PrintError

func PrintError(s_err errors.Error)

Function to print the error in Red.

func PushOrSet

func PushOrSet(args []string, pushvalue bool) (int, string)

func PushValue_Helper

func PushValue_Helper(set bool, param map[string]*Stack, vble, value string) (err_code int, err_str string)

Helper function to push or set a value in a stack.

func Pushparam_Helper

func Pushparam_Helper(param map[string]*Stack, isrestp bool, isnamep bool) (int, string)

Push value from the Top of the stack onto the parameter stack.

This is used by the \PUSH command with no arguments.

func Resolve

func Resolve(param string) (val value.Value, err_code int, err_str string)

The Resolve method is used to evaluate the input parameter

to the \SET / \PUSH / \POP / \UNSET and \ECHO commands. It
takes in a string, and resolves it to the appropriate value.
The input string can be broadly classified into 2 categories,
1. Parameters (here we will need to read the top value from
the parameter stack)
2. Actual values that can be converted to value.Value using
the StrToVal method.

func StrToVal

func StrToVal(param string) (val value.Value)

The StrToVal method converts the input string into a

value.Value type.

func ValToStr

func ValToStr(item value.Value) string

The ValToStr method converts the input value into a

string type.

Types

type Alias

type Alias struct {
	ShellCommand
}

Alias Command

func (*Alias) CommandCompletion

func (this *Alias) CommandCompletion() bool

func (*Alias) ExecCommand

func (this *Alias) ExecCommand(args []string) (int, string)

func (*Alias) MaxArgs

func (this *Alias) MaxArgs() int

func (*Alias) MinArgs

func (this *Alias) MinArgs() int

func (*Alias) Name

func (this *Alias) Name() string

func (*Alias) PrintHelp

func (this *Alias) PrintHelp(desc bool) (int, string)

type Connect

type Connect struct {
	ShellCommand
}

Connect Command

func (*Connect) CommandCompletion

func (this *Connect) CommandCompletion() bool

func (*Connect) ExecCommand

func (this *Connect) ExecCommand(args []string) (int, string)

func (*Connect) MaxArgs

func (this *Connect) MaxArgs() int

func (*Connect) MinArgs

func (this *Connect) MinArgs() int

func (*Connect) Name

func (this *Connect) Name() string

func (*Connect) PrintHelp

func (this *Connect) PrintHelp(desc bool) (int, string)
type Copyright struct {
	ShellCommand
}

Copyright Command

func (*Copyright) CommandCompletion

func (this *Copyright) CommandCompletion() bool

func (*Copyright) ExecCommand

func (this *Copyright) ExecCommand(args []string) (int, string)

func (*Copyright) MaxArgs

func (this *Copyright) MaxArgs() int

func (*Copyright) MinArgs

func (this *Copyright) MinArgs() int

func (*Copyright) Name

func (this *Copyright) Name() string

func (*Copyright) PrintHelp

func (this *Copyright) PrintHelp(desc bool) (int, string)

type Credential

type Credential map[string]string

type Credentials

type Credentials []Credential

func ToCreds

func ToCreds(credsFlag string) (Credentials, int, string)

type Disconnect

type Disconnect struct {
	ShellCommand
}

Disconnect Command

func (*Disconnect) CommandCompletion

func (this *Disconnect) CommandCompletion() bool

func (*Disconnect) ExecCommand

func (this *Disconnect) ExecCommand(args []string) (int, string)

func (*Disconnect) MaxArgs

func (this *Disconnect) MaxArgs() int

func (*Disconnect) MinArgs

func (this *Disconnect) MinArgs() int

func (*Disconnect) Name

func (this *Disconnect) Name() string

func (*Disconnect) PrintHelp

func (this *Disconnect) PrintHelp(desc bool) (int, string)

type Echo

type Echo struct {
	ShellCommand
}

Echo Command

func (*Echo) CommandCompletion

func (this *Echo) CommandCompletion() bool

func (*Echo) ExecCommand

func (this *Echo) ExecCommand(args []string) (int, string)

func (*Echo) MaxArgs

func (this *Echo) MaxArgs() int

func (*Echo) MinArgs

func (this *Echo) MinArgs() int

func (*Echo) Name

func (this *Echo) Name() string

func (*Echo) PrintHelp

func (this *Echo) PrintHelp(desc bool) (int, string)

type Exit

type Exit struct {
	ShellCommand
}

Exit and Quit Commands

func (*Exit) CommandCompletion

func (this *Exit) CommandCompletion() bool

func (*Exit) ExecCommand

func (this *Exit) ExecCommand(args []string) (int, string)

func (*Exit) MaxArgs

func (this *Exit) MaxArgs() int

func (*Exit) MinArgs

func (this *Exit) MinArgs() int

func (*Exit) Name

func (this *Exit) Name() string

func (*Exit) PrintHelp

func (this *Exit) PrintHelp(desc bool) (int, string)

type Help

type Help struct {
	ShellCommand
}

Help Command

func (*Help) CommandCompletion

func (this *Help) CommandCompletion() bool

func (*Help) ExecCommand

func (this *Help) ExecCommand(args []string) (int, string)

func (*Help) MaxArgs

func (this *Help) MaxArgs() int

func (*Help) MinArgs

func (this *Help) MinArgs() int

func (*Help) Name

func (this *Help) Name() string

func (*Help) PrintHelp

func (this *Help) PrintHelp(desc bool) (int, string)

type Pop

type Pop struct {
	ShellCommand
}

Pop Command

func (*Pop) CommandCompletion

func (this *Pop) CommandCompletion() bool

func (*Pop) ExecCommand

func (this *Pop) ExecCommand(args []string) (int, string)

func (*Pop) MaxArgs

func (this *Pop) MaxArgs() int

func (*Pop) MinArgs

func (this *Pop) MinArgs() int

func (*Pop) Name

func (this *Pop) Name() string

func (*Pop) PrintHelp

func (this *Pop) PrintHelp(desc bool) (int, string)

type Push

type Push struct {
	ShellCommand
}

Push Command

func (*Push) CommandCompletion

func (this *Push) CommandCompletion() bool

func (*Push) ExecCommand

func (this *Push) ExecCommand(args []string) (int, string)

func (*Push) MaxArgs

func (this *Push) MaxArgs() int

func (*Push) MinArgs

func (this *Push) MinArgs() int

func (*Push) Name

func (this *Push) Name() string

func (*Push) PrintHelp

func (this *Push) PrintHelp(desc bool) (int, string)

type Set

type Set struct {
	ShellCommand
}

Set Command

func (*Set) CommandCompletion

func (this *Set) CommandCompletion() bool

func (*Set) ExecCommand

func (this *Set) ExecCommand(args []string) (int, string)

func (*Set) MaxArgs

func (this *Set) MaxArgs() int

func (*Set) MinArgs

func (this *Set) MinArgs() int

func (*Set) Name

func (this *Set) Name() string

func (*Set) PrintHelp

func (this *Set) PrintHelp(desc bool) (int, string)

type ShellCommand

type ShellCommand interface {
	/* Name of the comand */
	Name() string
	/* Return true if included in shell command completion */
	CommandCompletion() bool
	/* Returns the Minimum number of input arguments required by the function */
	MinArgs() int
	/* Returns the Maximum number of input arguments allowed by the function */
	MaxArgs() int
	/* Method that implements the functionality */
	ExecCommand(args []string) (int, string)
	/* Print Help information for command and its usage with an example */
	PrintHelp(desc bool) (int, string)
}

Interface to be implemented by shell commands.

type Source

type Source struct {
	ShellCommand
}

Source Command

func (*Source) CommandCompletion

func (this *Source) CommandCompletion() bool

func (*Source) ExecCommand

func (this *Source) ExecCommand(args []string) (int, string)

func (*Source) MaxArgs

func (this *Source) MaxArgs() int

func (*Source) MinArgs

func (this *Source) MinArgs() int

func (*Source) Name

func (this *Source) Name() string

func (*Source) PrintHelp

func (this *Source) PrintHelp(desc bool) (int, string)

type Stack

type Stack []value.Value

Stack methods to be used for session parameters

func Stack_Helper

func Stack_Helper() *Stack

Helper function to create a stack.

func (*Stack) Len

func (stack *Stack) Len() int

func (*Stack) Pop

func (stack *Stack) Pop() (val value.Value, err_code int, err_str string)

Delete the top element in the stack. If the stack

is empty then print err stack empty

func (*Stack) Push

func (stack *Stack) Push(val value.Value)

Push input value val onto the stack

func (*Stack) SetTop

func (stack *Stack) SetTop(v value.Value) (err_code int, err_str string)

func (*Stack) Top

func (stack *Stack) Top() (val value.Value, err_code int, err_str string)

Return the top element in the stack. If the stack

is empty then return ZERO_VALUE.

type Unalias

type Unalias struct {
	ShellCommand
}

Unalias Command

func (*Unalias) CommandCompletion

func (this *Unalias) CommandCompletion() bool

func (*Unalias) ExecCommand

func (this *Unalias) ExecCommand(args []string) (int, string)

func (*Unalias) MaxArgs

func (this *Unalias) MaxArgs() int

func (*Unalias) MinArgs

func (this *Unalias) MinArgs() int

func (*Unalias) Name

func (this *Unalias) Name() string

func (*Unalias) PrintHelp

func (this *Unalias) PrintHelp(desc bool) (int, string)

type Unset

type Unset struct {
	ShellCommand
}

Unset Command

func (*Unset) CommandCompletion

func (this *Unset) CommandCompletion() bool

func (*Unset) ExecCommand

func (this *Unset) ExecCommand(args []string) (int, string)

func (*Unset) MaxArgs

func (this *Unset) MaxArgs() int

func (*Unset) MinArgs

func (this *Unset) MinArgs() int

func (*Unset) Name

func (this *Unset) Name() string

func (*Unset) PrintHelp

func (this *Unset) PrintHelp(desc bool) (int, string)

type Version

type Version struct {
	ShellCommand
}

Version Command

func (*Version) CommandCompletion

func (this *Version) CommandCompletion() bool

func (*Version) ExecCommand

func (this *Version) ExecCommand(args []string) (int, string)

func (*Version) MaxArgs

func (this *Version) MaxArgs() int

func (*Version) MinArgs

func (this *Version) MinArgs() int

func (*Version) Name

func (this *Version) Name() string

func (*Version) PrintHelp

func (this *Version) PrintHelp(desc bool) (int, string)

Jump to

Keyboard shortcuts

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