{"modulePath":"github.com/HashDataInc/packer","version":"v1.3.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package bootcommand\n\n## Constants\n\n```go\nconst KeyLeftShift uint32 = 0xFFE1\n```\n\n## Functions\n\n```go\nfunc GenerateExpressionSequence(command string) (expressionSequence, error)\n```\nGenerateExpressionSequence generates a sequence of expressions from the given command. This is the primary entry point to the boot command parser.\n\n```go\nfunc NewPCXTDriver(send SendCodeFunc, chunkSize int, interval time.Duration) *pcXTDriver\n```\nNewPCXTDriver creates a new boot command driver for VMs that expect PC-XT keyboard codes. \\`send\\` should send its argument to the VM. \\`chunkSize\\` should be the maximum number of keyboard codes to send to \\`send\\` at one time.\n\n```go\nfunc NewVNCDriver(c VNCKeyEvent, interval time.Duration) *vncDriver\n```\n\n```go\nfunc Parse(filename string, b []byte, opts ...Option) (interface{}, error)\n```\nParse parses the data from b using filename as information in the error messages.\n\n```go\nfunc ParseFile(filename string, opts ...Option) (i interface{}, err error)\n```\nParseFile parses the file identified by filename.\n\n```go\nfunc ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error)\n```\nParseReader parses the data from r using filename as information in the error messages.\n\n## Types\n\n```go\ntype BCDriver interface {\n\tSendKey(key rune, action KeyAction) error\n\tSendSpecial(special string, action KeyAction) error\n\t// Flush will be called when we want to send scancodes to the VM.\n\tFlush() error\n}\n```\nBCDriver is our access to the VM we want to type boot commands to\n\n```go\ntype BootConfig struct {\n\tRawBootGroupInterval string        `mapstructure:\"boot_keygroup_interval\"`\n\tRawBootWait          string        `mapstructure:\"boot_wait\"`\n\tBootCommand          []string      `mapstructure:\"boot_command\"`\n\tBootGroupInterval    time.Duration ``\n\tBootWait             time.Duration ``\n}\n```\n\n```go\nfunc (c *BootConfig) FlatBootCommand() string\n```\n\n```go\nfunc (c *BootConfig) Prepare(ctx *interpolate.Context) (errs []error)\n```\n\n```go\ntype Cloner interface {\n\tClone() interface{}\n}\n```\nCloner is implemented by any value that has a Clone method, which returns a copy of the value. This is mainly used for types which are not passed by value (e.g map, slice, chan) or structs that contain such types.\n\nThis is used in conjunction with the global state feature to create proper copies of the state to allow the parser to properly restore the state in the case of backtracking.\n\n```go\ntype KeyAction int\n```\nKeysAction represents what we want to do with a key press. It can take 3 states. We either want to: \\* press the key once \\* press and hold \\* press and release\n\n```go\nconst (\n\tKeyOn KeyAction = 1 \u003c\u003c iota\n\tKeyOff\n\tKeyPress\n)\n```\n\n```go\nfunc (k KeyAction) String() string\n```\n\n```go\ntype Option func(*parser) Option\n```\nOption is a function that can set an option on the parser. It returns the previous setting as an Option.\n\n```go\nfunc AllowInvalidUTF8(b bool) Option\n```\nAllowInvalidUTF8 creates an Option to allow invalid UTF-8 bytes. Every invalid UTF-8 byte is treated as a utf8.RuneError (U+FFFD) by character class matchers and is matched by the any matcher. The returned matched value, c.text and c.offset are NOT affected.\n\nThe default is false.\n\n```go\nfunc Debug(b bool) Option\n```\nDebug creates an Option to set the debug flag to b. When set to true, debugging information is printed to stdout while parsing.\n\nThe default is false.\n\n```go\nfunc Entrypoint(ruleName string) Option\n```\nEntrypoint creates an Option to set the rule name to use as entrypoint. The rule name must have been specified in the -alternate-entrypoints if generating the parser with the -optimize-grammar flag, otherwise it may have been optimized out. Passing an empty string sets the entrypoint to the first rule in the grammar.\n\nThe default is to start parsing at the first rule in the grammar.\n\n```go\nfunc GlobalStore(key string, value interface{}) Option\n```\nGlobalStore creates an Option to set a key to a certain value in the globalStore.\n\n```go\nfunc InitState(key string, value interface{}) Option\n```\nInitState creates an Option to set a key to a certain value in the global \"state\" store.\n\n```go\nfunc MaxExpressions(maxExprCnt uint64) Option\n```\nMaxExpressions creates an Option to stop parsing after the provided number of expressions have been parsed, if the value is 0 then the parser will parse for as many steps as needed (possibly an infinite number).\n\nThe default for maxExprCnt is 0.\n\n```go\nfunc Memoize(b bool) Option\n```\nMemoize creates an Option to set the memoize flag to b. When set to true, the parser will cache all results so each expression is evaluated only once. This guarantees linear parsing time even for pathological cases, at the expense of more memory and slower times for typical cases.\n\nThe default is false.\n\n```go\nfunc Recover(b bool) Option\n```\nRecover creates an Option to set the recover flag to b. When set to true, this causes the parser to recover from panics and convert it to an error. Setting it to false can be useful while debugging to access the full stack trace.\n\nThe default is true.\n\n```go\nfunc Statistics(stats *Stats, choiceNoMatch string) Option\n```\nStatistics adds a user provided Stats struct to the parser to allow the user to process the results after the parsing has finished. Also the key for the \"no match\" counter is set.\n\nExample usage:\n\n\tinput := \"input\"\n\tstats := Stats{}\n\t_, err := Parse(\"input-file\", []byte(input), Statistics(\u0026stats, \"no match\"))\n\tif err != nil {\n\t    log.Panicln(err)\n\t}\n\tb, err := json.MarshalIndent(stats.ChoiceAltCnt, \"\", \"  \")\n\tif err != nil {\n\t    log.Panicln(err)\n\t}\n\tfmt.Println(string(b))\n\n```go\ntype SendCodeFunc func([]string) error\n```\nSendCodeFunc will be called to send codes to the VM\n\n```go\ntype Stats struct {\n\t// ExprCnt counts the number of expressions processed during parsing\n\t// This value is compared to the maximum number of expressions allowed\n\t// (set by the MaxExpressions option).\n\tExprCnt uint64\n\n\t// ChoiceAltCnt is used to count for each ordered choice expression,\n\t// which alternative is used how may times.\n\t// These numbers allow to optimize the order of the ordered choice expression\n\t// to increase the performance of the parser\n\t//\n\t// The outer key of ChoiceAltCnt is composed of the name of the rule as well\n\t// as the line and the column of the ordered choice.\n\t// The inner key of ChoiceAltCnt is the number (one-based) of the matching alternative.\n\t// For each alternative the number of matches are counted. If an ordered choice does not\n\t// match, a special counter is incremented. The name of this counter is set with\n\t// the parser option Statistics.\n\t// For an alternative to be included in ChoiceAltCnt, it has to match at least once.\n\tChoiceAltCnt map[string]map[string]int\n}\n```\nStats stores some statistics, gathered during parsing\n\n```go\ntype VNCConfig struct {\n\tBootConfig `mapstructure:\",squash\"`\n\tDisableVNC bool `mapstructure:\"disable_vnc\"`\n\t// time in ms to wait between each key press\n\tRawBootKeyInterval string        `mapstructure:\"boot_key_interval\"`\n\tBootKeyInterval    time.Duration ``\n}\n```\n\n```go\nfunc (c *VNCConfig) Prepare(ctx *interpolate.Context) (errs []error)\n```\n\n```go\ntype VNCKeyEvent interface {\n\tKeyEvent(uint32, bool) error\n}\n```\n\n","path":"github.com/HashDataInc/packer/common/bootcommand","name":"bootcommand","synopsis":"","isRedistributable":true}
