From cba4d3235f13a46e14227edb01e260dee243218e Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Fri, 13 Apr 2018 13:18:55 -0700 Subject: [PATCH] cleanup --- .../vmware/common/step_type_boot_command.go | 2 -- common/boot_command/boot_command_ast.go | 19 +++++++------------ common/boot_command/pc_at_driver.go | 1 + 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/builder/vmware/common/step_type_boot_command.go b/builder/vmware/common/step_type_boot_command.go index 6cfb196e3..6821b8e1b 100644 --- a/builder/vmware/common/step_type_boot_command.go +++ b/builder/vmware/common/step_type_boot_command.go @@ -51,7 +51,6 @@ func (s *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateBag) vncPort := state.Get("vnc_port").(uint) vncPassword := state.Get("vnc_password") - // ---------------- // Wait the for the vm to boot. if int64(s.BootWait) > 0 { ui.Say(fmt.Sprintf("Waiting %s for boot...", s.BootWait.String())) @@ -62,7 +61,6 @@ func (s *StepTypeBootCommand) Run(ctx context.Context, state multistep.StateBag) return multistep.ActionHalt } } - // ---------------- var pauseFn multistep.DebugPauseFn if debug { diff --git a/common/boot_command/boot_command_ast.go b/common/boot_command/boot_command_ast.go index 9a5ec1eed..0fb8fa470 100644 --- a/common/boot_command/boot_command_ast.go +++ b/common/boot_command/boot_command_ast.go @@ -11,8 +11,7 @@ import ( /* TODO: * tests - * fix vbox tests - * comments + * fix vbox tests * lower-case specials * pc-at abstraction * check that `` works. It's different now. @@ -33,15 +32,6 @@ const ( KeyPress ) -func onOffToAction(t string) KeyAction { - if strings.EqualFold(t, "on") { - return KeyOn - } else if strings.EqualFold(t, "off") { - return KeyOff - } - panic(fmt.Sprintf("Unknown state '%s'. Expecting On or Off.", t)) -} - func (k KeyAction) String() string { switch k { case KeyOn: @@ -60,6 +50,7 @@ type expression interface { type expressionSequence []expression +// Do executes every expression in the sequence and then finalizes the driver. func (s expressionSequence) Do(ctx context.Context, b BCDriver) error { for _, exp := range s { if err := exp.Do(ctx, b); err != nil { @@ -70,7 +61,7 @@ func (s expressionSequence) Do(ctx context.Context, b BCDriver) error { } // GenerateExpressionSequence generates a sequence of expressions from the -// given command. +// given command. This is the primary entry point to the boot command parser. func GenerateExpressionSequence(command string) (expressionSequence, error) { got, err := ParseReader("", strings.NewReader(command)) if err != nil { @@ -90,6 +81,8 @@ type waitExpression struct { d time.Duration } +// Do waits the amount of time described by the expression. It is cancellable +// through the context. func (w *waitExpression) Do(ctx context.Context, _ BCDriver) error { log.Printf("[INFO] Waiting %s", w.d) select { @@ -109,6 +102,7 @@ type specialExpression struct { action KeyAction } +// Do sends the special command to the driver, along with the key action. func (s *specialExpression) Do(ctx context.Context, driver BCDriver) error { return driver.SendSpecial(s.s, s.action) } @@ -122,6 +116,7 @@ type literal struct { action KeyAction } +// Do sends the key to the driver, along with the key action. func (l *literal) Do(ctx context.Context, driver BCDriver) error { return driver.SendKey(l.s, l.action) } diff --git a/common/boot_command/pc_at_driver.go b/common/boot_command/pc_at_driver.go index b89dcc081..a3398177e 100644 --- a/common/boot_command/pc_at_driver.go +++ b/common/boot_command/pc_at_driver.go @@ -174,6 +174,7 @@ func (d *pcATDriver) SendSpecial(special string, action KeyAction) error { return nil } +// send stores the codes in an internal buffer. Use finalize to flush them. func (d *pcATDriver) send(codes []string) { d.buffer = append(d.buffer, codes) }