cmd

package
v0.0.0-...-1c8de56 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2019 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Con Consoler interface implementation.

View Source
var ConfigCmd = &cobra.Command{
	Use:                   "config SUBCOMMAND",
	DisableFlagsInUseLine: true,
	Short:                 "Manage slingconfig settings",
	Long:                  "Manage slingconfig settings",
	Example: `
	# View slingconfig settings
	sling config view`,
}

ConfigCmd command.

View Source
var Events = [...]string{
	"unknows_event",
	"console_set_flat",
	"log_set_level",
	"console_set_level",
	"wildcard_set",
	"active_enpoint_set",
}

Events event names

View Source
var LogCmd = &cobra.Command{
	Use:                   "log SUBCOMMAND",
	DisableFlagsInUseLine: true,
	Short:                 "Manage sling logs",
	Long: `
	Manage sling log file`,
	Example: `
	# View sling log file
	sling log view

	# Clean sling log file
	sling log clean

	# Log and Console levels
	PanicLevel [0]: Highest level of severity
	FatalLevel [1]: Logs and then calls logger.Exit(1).
	ErrorLevel [2]: Used for errors that should definitely be noted.
	WarnLevel  [3]: Non-critical entries that deserve eyes.
	InfoLevel  [4]: General operational entries about what's going on inside the application.
	DebugLevel [5]: Usually only enabled when debugging. Very verbose logging.
	TraceLevel [6]: Designates finer-grained informational events than the Debug.`,
}

LogCmd command.

View Source
var LogcleanCmd = &cobra.Command{
	Use:   "clean",
	Short: "Clean sling log file",
	Long: `
	Clean sling log file`,
	Example: `
	# Clean sling log file using Linux truncate command
	sling log clean`,
	Run: logcleanRun,
}

LogcleanCmd command.

View Source
var LogviewCmd = &cobra.Command{
	Use:   "view",
	Short: "View sling log file",
	Long: `
	View sling log file`,
	Example: `
	# View sling log using Linux cat command
	sling log view`,
	Run: logviewRun,
}

LogviewCmd command.

View Source
var RequestCmd = &cobra.Command{
	Use:                   "request SUBCOMMAND",
	DisableFlagsInUseLine: true,
	Short:                 "Process sling requests",
	Long: `
	Sling request managment`,
	Example: `
	Send a single request.
	sling request send --filename=m000001-tpf-request.dat`,
}

RequestCmd command.

View Source
var RootCmd = &cobra.Command{
	Use:                   "sling",
	DisableFlagsInUseLine: true,
	Short:                 "sling network traffic emulator",
	Long: `
	sling is a tool to send files to the endpoint(s),
	setting trottling and delays between concurrent requests.`,
	Example: `
	# View current sling config
	sling config view
	
	# Send a single file to specified endpoint
	sling request send -f myfile.dat -a myhost.com -p 9080`,
}

RootCmd sling root command

View Source
var SessionID string

SessionID Send command session ID

View Source
var ViewCmd = &cobra.Command{
	Use:   "view",
	Short: "View slingconfig settings",
	Long: `
	View slingconfig settings`,
	Example: `
	# View current slingconfig settings
	sling config view`,
	Run: viewRun,
}

ViewCmd command.

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately.

func LoadConfig

func LoadConfig(path string, logger slog.Logger) (sconf *conf.SlingConfig, err error)

LoadConfig loads configuration from the file.

func NewSendEmul

func NewSendEmul(sendArgs *emul.SendArgs) (em *emul.Emul, err error)

NewSendEmul creates new send emulator.

func PrintObj

func PrintObj(obj interface{}, w io.Writer) error

PrintObj impl

Types

type BoolVal

type BoolVal struct {
	Value   bool
	Default bool
}

BoolVal flag value

type Commander

type Commander interface {
}

Commander command interface.

type EventID

type EventID int

EventID enum

const (
	// UnknownEvent unknown event
	UnknownEvent EventID = iota
	// ConsoleSetFlat sets console output flat with no timestamp or fields
	ConsoleSetFlat
	// LogSetLevel sets log level
	LogSetLevel
	// ConsoleSetLevel sets console level
	ConsoleSetLevel
	// WildcardSet sets the wildcard flag
	WildcardSet
	// ActiveEndpointSet sent the active enpoint index
	ActiveEndpointSet
)

type Flag

type Flag struct {
	ID        FlagID
	Name      string
	Shorthand string
	Usage     string
	Flagset   *Flags
	Type      FlagType
	Value     interface{}
	Event     *event.Dispatcher
}

A Flag represents the state of a flag.

func NewFlag

func NewFlag(id FlagID, flagType FlagType) *Flag

NewFlag returns a new, empty flag set with the specified it, name, etc.

func NewFlagBool

func NewFlagBool(id FlagID, defaultValue bool) *Flag

NewFlagBool returns a new bool flag.

func NewFlagStr

func NewFlagStr(id FlagID, defaultValue string) *Flag

NewFlagStr returns a new string flag.

func NewFlagUint

func NewFlagUint(id FlagID, defaultValue uint) *Flag

NewFlagUint returns a new uint flag.

func (Flag) AddEvent

func (f Flag) AddEvent(name interface{}, performing interface{}, parameters ...interface{}) (flag bool, err error)

AddEvent adds flag event

func (Flag) Changed

func (f Flag) Changed() (bool, error)

Changed returns true if default value was changed.

func (*Flag) EqualDefault

func (f *Flag) EqualDefault(val interface{}) bool

EqualDefault returns bool if value is equal.

func (*Flag) EqualVal

func (f *Flag) EqualVal(val interface{}) bool

EqualVal returns bool if value is equal.

func (Flag) FireEvent

func (f Flag) FireEvent(event interface{}, parameters ...interface{}) (err error)

FireEvent fire flag event.

func (Flag) SetValue

func (f Flag) SetValue(val interface{})

SetValue sets flag value.

type FlagID

type FlagID int

FlagID enum

const (
	// UnknownFlag unknown flag, " ", Unknown Flag.
	UnknownFlag FlagID = iota
	// Address endpoint IP, DNS name, or HTTP address, -a, --address
	Address
	// CltType network client type, TCP or HttpPost, -c, --cltType
	CltType
	// ConHis write histogram to console, -y, --conHis
	ConHis
	// CxnLim limit the number of concurrent connections, -l, cxnLim
	CxnLim
	// CxnNum number of concurrent connections, -n, --cxnNum
	CxnNum
	// Dir directory to send files from, -d, --dir
	Dir
	// Endpoint active endpoint index in SLINGCONFIG, zero-based, -i, --endpont
	Endpoint
	// File file path or filename to send, -f, --file
	File
	// LogHis write histogram to log file, -g, --logHis
	LogHis
	// Port endpoint port number, -p, --port
	Port
	// RateMin send rate per minute, -m, --rateMin
	RateMin
	// RateSec send rate per second, -s, --rateSec
	RateSec
	// Repeat send repeat count, -r, --repeat
	Repeat
	// SaveReq save requests, -q, --saveReq
	SaveReq
	// SaveReqDir directory to save requests, -k, --saveReqDir
	SaveReqDir
	// SaveRes save responses, -o, --saveRes
	SaveRes
	// SaveResDir directory to save response, -j, --saveResDir
	SaveResDir
	// SleepMs delay after each repeated request, -e, --sleepMs
	SleepMs
	// TmoCxn network client dial timeout, -u, --tmoCxn
	TmoCxn
	// TmoRdS network client timeout for Read calls, -v, tmoRdS
	TmoRdS
	// TmoSec network client timeout, -t, --tmoSec
	TmoSec
	// TmoWrS network client timeout for Write calls, -x, --tmoWrS
	TmoWrS
	// Wildcard file name matching wildcard, -w, --wildcard
	Wildcard
	// ConFlat set console flat output without timestamp and fields, - , --conFlat
	ConFlat
	// ConLvl console output level, --, conLvl
	ConLvl
	// LogLvl log output level, --, logLvl
	LogLvl
)

func (FlagID) Flag

func (i FlagID) Flag() string

func (FlagID) String

func (i FlagID) String() string

type FlagType

type FlagType int

FlagType enum

const (
	// UnknownType unknown flag type, " ", Unknown Type
	UnknownType FlagType = iota
	// StringType flag
	StringType
	// BoolType flag
	BoolType
	// UintType flag
	UintType
	// UintSliceType flag
	UintSliceType
)

type Flagmapper

type Flagmapper interface {
	SetExplicit()
	Add(flag *Flag, persist bool)
	GetFlagmap() map[FlagID]*Flag
	GetExplicit() map[FlagID]*Flag
	ResolveSendArgs(args *emul.SendArgs) (err error)
	AddEvent(flagID FlagID, name interface{}, performing interface{}, parameters ...interface{}) (flag bool, err error)
	SetActiveEndpoint(eptIdx uint)
}

Flagmapper builds command flags.

var RootFlags Flagmapper

RootFlags command flags

func NewCmdFlags

func NewCmdFlags(cmd *cobra.Command, id ID, slconf *conf.SlingConfig) (flagmapper Flagmapper, err error)

NewCmdFlags adds all command flags for the specific command by ID.

func NewFlagMap

func NewFlagMap(cmd *cobra.Command, filer sio.Filer) Flagmapper

NewFlagMap creates a new Flagmapper instance.

type Flags

type Flags struct {
	Command    *cobra.Command
	Map        map[FlagID]*Flag
	Explicit   map[FlagID]*Flag
	Filer      sio.Filer
	Flagmapper Flagmapper
}

Flags has all command flags.

func (Flags) Add

func (fs Flags) Add(flag *Flag, persist bool)

Add a flag to the command flag set.

func (Flags) AddEvent

func (fs Flags) AddEvent(flagID FlagID, name interface{}, performing interface{}, parameters ...interface{}) (flag bool, err error)

AddEvent adds flag event.

func (Flags) GetExplicit

func (fs Flags) GetExplicit() map[FlagID]*Flag

GetExplicit returns the explicit flag map.

func (Flags) GetFlagmap

func (fs Flags) GetFlagmap() map[FlagID]*Flag

GetFlagmap returns the flag map.

func (Flags) ResolveSendArgs

func (fs Flags) ResolveSendArgs(args *emul.SendArgs) (err error)

ResolveSendArgs resolves send arguments from command flags.

func (Flags) SetActiveEndpoint

func (fs Flags) SetActiveEndpoint(eptIdx uint)

SetActiveEndpoint sets active endpoint

func (Flags) SetExplicit

func (fs Flags) SetExplicit()

SetExplicit finds the flags set explicitly and addes them to the Explicit map.

type ID

type ID int

ID enum

const (
	// CmdUnknown unknown command
	CmdUnknown ID = iota
	// CmdRoot command
	CmdRoot
	// CmdSend send command
	CmdSend
	// CmdView view command
	CmdView
)

type StrVal

type StrVal struct {
	Value   string
	Default string
}

StrVal flag value

type UintVal

type UintVal struct {
	Value   uint
	Default uint
}

UintVal flag value

Jump to

Keyboard shortcuts

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