FlagSet returns a FlagSet with Packer SDK Ui support built-in
(n string)
| 62 | |
| 63 | // FlagSet returns a FlagSet with Packer SDK Ui support built-in |
| 64 | func (m *Meta) FlagSet(n string) *flag.FlagSet { |
| 65 | f := flag.NewFlagSet(n, flag.ContinueOnError) |
| 66 | |
| 67 | // Create an io.Writer that writes to our Ui properly for errors. |
| 68 | // This is kind of a hack, but it does the job. Basically: create |
| 69 | // a pipe, use a scanner to break it into lines, and output each line |
| 70 | // to the UI. Do this forever. |
| 71 | errR, errW := io.Pipe() |
| 72 | errScanner := bufio.NewScanner(errR) |
| 73 | go func() { |
| 74 | for errScanner.Scan() { |
| 75 | m.Ui.Error(errScanner.Text()) |
| 76 | } |
| 77 | }() |
| 78 | f.SetOutput(errW) |
| 79 | |
| 80 | return f |
| 81 | } |
| 82 | |
| 83 | // ValidateFlags should be called after parsing flags to validate the |
| 84 | // given flags |
no test coverage detected