Skip to content

Commit

Permalink
command: remove unused FlagSetFlags enum
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lbajolet-hashicorp authored and nywilken committed Oct 16, 2023
1 parent a1722ab commit 020f18e
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 24 deletions.
2 changes: 1 addition & 1 deletion command/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion command/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion command/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion command/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion command/hcl2_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion command/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion command/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 2 additions & 15 deletions command/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion command/plugins_required.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion command/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 020f18e

Please sign in to comment.