Browse Source

feat: add force flag

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

6
main.go

@ -75,6 +75,11 @@ func main() {
Usage: "Machine-readable output",
EnvVar: "PLUGIN_READABLE",
},
cli.BoolFlag{
Name: "force",
Usage: "Force a build to continue if artifacts exist, deletes existing artifacts",
EnvVar: "PLUGIN_FORCE",
},
}
app.Version = Version
@ -119,6 +124,7 @@ func run(c *cli.Context) error {
Debug: c.Bool("debug"),
Parallel: c.Bool("parallel"),
Readable: c.Bool("readable"),
Force: c.Bool("force"),
},
}

5
plugin.go

@ -24,6 +24,7 @@ type (
Debug bool
Parallel bool
Readable bool
Force bool
}
// Plugin values
@ -103,6 +104,10 @@ func pkBuild(config Config) *exec.Cmd {
args = append(args, "-machine-readable")
}
if config.Force {
args = append(args, "-force")
}
args = append(args, config.Template)
return exec.Command(
"packer",

10
plugin_test.go

@ -113,6 +113,16 @@ func Test_pkBuild(t *testing.T) {
},
want: exec.Command("packer", "build", "-machine-readable", "foo.json"),
},
{
name: "add force flag",
args: args{
config: Config{
Template: "foo.json",
Force: true,
},
},
want: exec.Command("packer", "build", "-force", "foo.json"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

Loading…
Cancel
Save