github.com/yoheimuta/protolint@v0.49.8-0.20240515023657-4ecaebb7575d/internal/cmd/subcmds/list/flags.go (about)

     1  package list
     2  
     3  import (
     4  	"flag"
     5  
     6  	"github.com/yoheimuta/protolint/internal/cmd/subcmds"
     7  
     8  	"github.com/yoheimuta/protolint/internal/addon/plugin/shared"
     9  )
    10  
    11  // Flags represents a set of lint flag parameters.
    12  type Flags struct {
    13  	*flag.FlagSet
    14  
    15  	Plugins []shared.RuleSet
    16  }
    17  
    18  // NewFlags creates a new Flags.
    19  func NewFlags(
    20  	args []string,
    21  ) (Flags, error) {
    22  	f := Flags{
    23  		FlagSet: flag.NewFlagSet("list", flag.ExitOnError),
    24  	}
    25  	var pf subcmds.PluginFlag
    26  
    27  	f.Var(
    28  		&pf,
    29  		"plugin",
    30  		`plugins to provide custom lint rule set. Note that it's necessary to specify it as path format'`,
    31  	)
    32  
    33  	_ = f.Parse(args)
    34  
    35  	plugins, err := pf.BuildPlugins(false)
    36  	if err != nil {
    37  		return Flags{}, err
    38  	}
    39  	f.Plugins = plugins
    40  	return f, nil
    41  }