Browse Source

feat: add machine readable flag

update-packer-186
Bo-Yi Wu 7 years ago
parent
commit
9753e381c0
  1. 6
      main.go
  2. 5
      plugin.go
  3. 10
      plugin_test.go

6
main.go

@ -70,6 +70,11 @@ func main() {
Usage: "Disable parallelization (on by default)", Usage: "Disable parallelization (on by default)",
EnvVar: "PLUGIN_PARALLEL", EnvVar: "PLUGIN_PARALLEL",
}, },
cli.BoolFlag{
Name: "readable",
Usage: "Machine-readable output",
EnvVar: "PLUGIN_READABLE",
},
} }
app.Version = Version app.Version = Version
@ -113,6 +118,7 @@ func run(c *cli.Context) error {
Color: c.Bool("color"), Color: c.Bool("color"),
Debug: c.Bool("debug"), Debug: c.Bool("debug"),
Parallel: c.Bool("parallel"), Parallel: c.Bool("parallel"),
Readable: c.Bool("readable"),
}, },
} }

5
plugin.go

@ -23,6 +23,7 @@ type (
Color bool Color bool
Debug bool Debug bool
Parallel bool Parallel bool
Readable bool
} }
// Plugin values // Plugin values
@ -98,6 +99,10 @@ func pkBuild(config Config) *exec.Cmd {
args = append(args, "-debug") args = append(args, "-debug")
} }
if config.Readable {
args = append(args, "-machine-readable")
}
args = append(args, config.Template) args = append(args, config.Template)
return exec.Command( return exec.Command(
"packer", "packer",

10
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"), 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 { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {

Loading…
Cancel
Save