From 35f7cab47c0283410a36a278eeee41ce99f1dde1 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Fri, 6 Oct 2023 10:48:31 -0400 Subject: [PATCH] command: remove unused FlagSetFlags enum The enumeration for FlagSetFlags, which presumably was added when the Meta structure was introduced, aims to pre-populate the flagset for a subcommand with a series of arguments. However, despite it being documented, it is actually not used, and therefore can safely be removed from the codebase. --- command/build.go | 2 +- command/console.go | 2 +- command/fix.go | 2 +- command/fmt.go | 2 +- command/hcl2_upgrade.go | 2 +- command/init.go | 2 +- command/inspect.go | 2 +- command/meta.go | 17 ++--------------- command/plugins_required.go | 2 +- command/validate.go | 2 +- 10 files changed, 11 insertions(+), 24 deletions(-) diff --git a/command/build.go b/command/build.go index c77687c3586..94361807407 100644 --- a/command/build.go +++ b/command/build.go @@ -43,7 +43,7 @@ func (c *BuildCommand) Run(args []string) int { func (c *BuildCommand) ParseArgs(args []string) (*BuildArgs, int) { var cfg BuildArgs - flags := c.Meta.FlagSet("build", FlagSetBuildFilter|FlagSetVars) + flags := c.Meta.FlagSet("build") flags.Usage = func() { c.Ui.Say(c.Help()) } cfg.AddFlagSets(flags) if err := flags.Parse(args); err != nil { diff --git a/command/console.go b/command/console.go index f942ec4bd4f..da24a06150e 100644 --- a/command/console.go +++ b/command/console.go @@ -43,7 +43,7 @@ func (c *ConsoleCommand) Run(args []string) int { func (c *ConsoleCommand) ParseArgs(args []string) (*ConsoleArgs, int) { var cfg ConsoleArgs - flags := c.Meta.FlagSet("console", FlagSetVars) + flags := c.Meta.FlagSet("console") flags.Usage = func() { c.Ui.Say(c.Help()) } cfg.AddFlagSets(flags) if err := flags.Parse(args); err != nil { diff --git a/command/fix.go b/command/fix.go index 708be59717d..07bc8021e80 100644 --- a/command/fix.go +++ b/command/fix.go @@ -36,7 +36,7 @@ func (c *FixCommand) Run(args []string) int { func (c *FixCommand) ParseArgs(args []string) (*FixArgs, int) { var cfg FixArgs - flags := c.Meta.FlagSet("fix", FlagSetNone) + flags := c.Meta.FlagSet("fix") flags.Usage = func() { c.Ui.Say(c.Help()) } cfg.AddFlagSets(flags) if err := flags.Parse(args); err != nil { diff --git a/command/fmt.go b/command/fmt.go index 095a6fc8c69..3a70bcf187d 100644 --- a/command/fmt.go +++ b/command/fmt.go @@ -28,7 +28,7 @@ func (c *FormatCommand) Run(args []string) int { func (c *FormatCommand) ParseArgs(args []string) (*FormatArgs, int) { var cfg FormatArgs - flags := c.Meta.FlagSet("format", FlagSetNone) + flags := c.Meta.FlagSet("format") flags.Usage = func() { c.Ui.Say(c.Help()) } cfg.AddFlagSets(flags) if err := flags.Parse(args); err != nil { diff --git a/command/hcl2_upgrade.go b/command/hcl2_upgrade.go index 7802d409875..8295e4e8ae0 100644 --- a/command/hcl2_upgrade.go +++ b/command/hcl2_upgrade.go @@ -47,7 +47,7 @@ func (c *HCL2UpgradeCommand) Run(args []string) int { func (c *HCL2UpgradeCommand) ParseArgs(args []string) (*HCL2UpgradeArgs, int) { var cfg HCL2UpgradeArgs - flags := c.Meta.FlagSet("hcl2_upgrade", FlagSetNone) + flags := c.Meta.FlagSet("hcl2_upgrade") flags.Usage = func() { c.Ui.Say(c.Help()) } cfg.AddFlagSets(flags) if err := flags.Parse(args); err != nil { diff --git a/command/init.go b/command/init.go index 709e8ab0fdf..71332d57d25 100644 --- a/command/init.go +++ b/command/init.go @@ -37,7 +37,7 @@ func (c *InitCommand) Run(args []string) int { func (c *InitCommand) ParseArgs(args []string) (*InitArgs, int) { var cfg InitArgs - flags := c.Meta.FlagSet("init", 0) + flags := c.Meta.FlagSet("init") flags.Usage = func() { c.Ui.Say(c.Help()) } cfg.AddFlagSets(flags) if err := flags.Parse(args); err != nil { diff --git a/command/inspect.go b/command/inspect.go index 7a77ab76bb8..7e5ed316650 100644 --- a/command/inspect.go +++ b/command/inspect.go @@ -28,7 +28,7 @@ func (c *InspectCommand) Run(args []string) int { func (c *InspectCommand) ParseArgs(args []string) (*InspectArgs, int) { var cfg InspectArgs - flags := c.Meta.FlagSet("inspect", FlagSetVars) + flags := c.Meta.FlagSet("inspect") flags.Usage = func() { c.Ui.Say(c.Help()) } cfg.AddFlagSets(flags) if err := flags.Parse(args); err != nil { diff --git a/command/meta.go b/command/meta.go index 1989027499b..87ed70b906b 100644 --- a/command/meta.go +++ b/command/meta.go @@ -22,16 +22,6 @@ import ( "github.com/hashicorp/packer/version" ) -// FlagSetFlags is an enum to define what flags are present in the -// default FlagSet returned by Meta.FlagSet -type FlagSetFlags uint - -const ( - FlagSetNone FlagSetFlags = 0 - FlagSetBuildFilter FlagSetFlags = 1 << iota - FlagSetVars -) - // Meta contains the meta-options and functionality that nearly every // Packer command inherits. type Meta struct { @@ -72,11 +62,8 @@ func (m *Meta) Core(tpl *template.Template, cla *MetaArgs) (*packer.Core, error) return core, nil } -// FlagSet returns a FlagSet with the common flags that every -// command implements. The exact behavior of FlagSet can be configured -// using the flags as the second parameter, for example to disable -// build settings on the commands that don't handle builds. -func (m *Meta) FlagSet(n string, _ FlagSetFlags) *flag.FlagSet { +// FlagSet returns a FlagSet with Packer SDK Ui support built-in +func (m *Meta) FlagSet(n string) *flag.FlagSet { f := flag.NewFlagSet(n, flag.ContinueOnError) // Create an io.Writer that writes to our Ui properly for errors. diff --git a/command/plugins_required.go b/command/plugins_required.go index 04f86b3628c..7776b19210b 100644 --- a/command/plugins_required.go +++ b/command/plugins_required.go @@ -54,7 +54,7 @@ func (c *PluginsRequiredCommand) Run(args []string) int { func (c *PluginsRequiredCommand) ParseArgs(args []string) (*PluginsRequiredArgs, int) { var cfg PluginsRequiredArgs - flags := c.Meta.FlagSet("plugins required", 0) + flags := c.Meta.FlagSet("plugins required") flags.Usage = func() { c.Ui.Say(c.Help()) } cfg.AddFlagSets(flags) if err := flags.Parse(args); err != nil { diff --git a/command/validate.go b/command/validate.go index 60199bdbf71..5e40a5f9530 100644 --- a/command/validate.go +++ b/command/validate.go @@ -31,7 +31,7 @@ func (c *ValidateCommand) Run(args []string) int { func (c *ValidateCommand) ParseArgs(args []string) (*ValidateArgs, int) { var cfg ValidateArgs - flags := c.Meta.FlagSet("validate", FlagSetBuildFilter|FlagSetVars) + flags := c.Meta.FlagSet("validate") flags.Usage = func() { c.Ui.Say(c.Help()) } cfg.AddFlagSets(flags) if err := flags.Parse(args); err != nil {