From 9753e381c0b262a25f9a14c2929aefed6f0425d0 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sat, 28 Jul 2018 22:40:09 +0800 Subject: [PATCH] feat: add machine readable flag --- main.go | 6 ++++++ plugin.go | 5 +++++ plugin_test.go | 10 ++++++++++ 3 files changed, 21 insertions(+) diff --git a/main.go b/main.go index 4c197ef..31ae1ef 100644 --- a/main.go +++ b/main.go @@ -70,6 +70,11 @@ func main() { Usage: "Disable parallelization (on by default)", EnvVar: "PLUGIN_PARALLEL", }, + cli.BoolFlag{ + Name: "readable", + Usage: "Machine-readable output", + EnvVar: "PLUGIN_READABLE", + }, } app.Version = Version @@ -113,6 +118,7 @@ func run(c *cli.Context) error { Color: c.Bool("color"), Debug: c.Bool("debug"), Parallel: c.Bool("parallel"), + Readable: c.Bool("readable"), }, } diff --git a/plugin.go b/plugin.go index 2a38a1d..053e353 100644 --- a/plugin.go +++ b/plugin.go @@ -23,6 +23,7 @@ type ( Color bool Debug bool Parallel bool + Readable bool } // Plugin values @@ -98,6 +99,10 @@ func pkBuild(config Config) *exec.Cmd { args = append(args, "-debug") } + if config.Readable { + args = append(args, "-machine-readable") + } + args = append(args, config.Template) return exec.Command( "packer", diff --git a/plugin_test.go b/plugin_test.go index 06fdfa8..9311b79 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -103,6 +103,16 @@ func Test_pkBuild(t *testing.T) { }, want: exec.Command("packer", "build", "-parallel=true", "-color=true", "-debug", "foo.json"), }, + { + name: "add machine readable flag", + args: args{ + config: Config{ + Template: "foo.json", + Readable: true, + }, + }, + want: exec.Command("packer", "build", "-machine-readable", "foo.json"), + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {