MCPcopy
hub / github.com/hashicorp/packer / ParseArgs

Method ParseArgs

command/plugins_install.go:91–122  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

89}
90
91func (c *PluginsInstallCommand) ParseArgs(args []string) (*PluginsInstallArgs, int) {
92 pa := &PluginsInstallArgs{}
93
94 flags := c.Meta.FlagSet("plugins install")
95 flags.Usage = func() { c.Ui.Say(c.Help()) }
96 pa.AddFlagSets(flags)
97 err := flags.Parse(args)
98 if err != nil {
99 c.Ui.Error(fmt.Sprintf("Failed to parse options: %s", err))
100 return pa, 1
101 }
102
103 args = flags.Args()
104 if len(args) < 1 || len(args) > 2 {
105 c.Ui.Error(fmt.Sprintf("Invalid arguments, expected either 1 or 2 positional arguments, got %d", len(args)))
106 flags.Usage()
107 return pa, 1
108 }
109
110 if len(args) == 2 {
111 pa.Version = args[1]
112 }
113
114 if pa.Path != "" && pa.Version != "" {
115 c.Ui.Error("Invalid arguments: a version cannot be specified when using --path to install a local plugin binary")
116 flags.Usage()
117 return pa, 1
118 }
119
120 pa.PluginIdentifier = args[0]
121 return pa, 0
122}
123
124func (c *PluginsInstallCommand) RunContext(buildCtx context.Context, args *PluginsInstallArgs) int {
125 opts := plugingetter.ListInstallationsOptions{

Callers 1

RunMethod · 0.95

Calls 6

HelpMethod · 0.95
AddFlagSetsMethod · 0.95
FlagSetMethod · 0.80
ParseMethod · 0.65
ErrorMethod · 0.65
SayMethod · 0.45

Tested by

no test coverage detected