-
Notifications
You must be signed in to change notification settings - Fork 201
/
plugins.go
163 lines (138 loc) · 5.19 KB
/
plugins.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package main
import (
"get.porter.sh/porter/pkg/pkgmgmt"
"get.porter.sh/porter/pkg/plugins"
"get.porter.sh/porter/pkg/porter"
"github.com/spf13/cobra"
)
func buildPluginsCommands(p *porter.Porter) *cobra.Command {
cmd := &cobra.Command{
Use: "plugins",
Aliases: []string{"plugin"},
Short: "Plugin commands. Plugins enable Porter to work on different cloud providers and systems.",
Annotations: map[string]string{
"group": "resource",
},
}
cmd.AddCommand(buildPluginsListCommand(p))
cmd.AddCommand(buildPluginSearchCommand(p))
cmd.AddCommand(buildPluginShowCommand(p))
cmd.AddCommand(BuildPluginInstallCommand(p))
cmd.AddCommand(BuildPluginUninstallCommand(p))
cmd.AddCommand(buildPluginRunCommand(p))
return cmd
}
func buildPluginsListCommand(p *porter.Porter) *cobra.Command {
opts := porter.PrintPluginsOptions{}
cmd := &cobra.Command{
Use: "list",
Short: "List installed plugins",
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.ParseFormat()
},
RunE: func(cmd *cobra.Command, args []string) error {
return p.PrintPlugins(opts)
},
}
cmd.Flags().StringVarP(&opts.RawFormat, "output", "o", "table",
"Output format, allowed values are: table, json, yaml")
return cmd
}
func buildPluginSearchCommand(p *porter.Porter) *cobra.Command {
opts := porter.SearchOptions{
Type: "plugin",
}
cmd := &cobra.Command{
Use: "search [QUERY]",
Short: "Search available plugins",
Long: `Search available plugins. You can specify an optional plugin name query, where the results are filtered by plugins whose name contains the query term.
By default the community plugin index at https://cdn.porter.sh/plugins/index.json is searched. To search from a mirror, set the environment variable PORTER_MIRROR, or mirror in the Porter config file, with the value to replace https://cdn.porter.sh with.`,
Example: ` porter plugin search
porter plugin search azure
porter plugin search -o json`,
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.Validate(args)
},
RunE: func(cmd *cobra.Command, args []string) error {
return p.SearchPackages(opts)
},
}
flags := cmd.Flags()
flags.StringVarP(&opts.RawFormat, "output", "o", "table",
"Output format, allowed values are: table, json, yaml")
flags.StringVar(&opts.Mirror, "mirror", pkgmgmt.DefaultPackageMirror,
"Mirror of official Porter assets")
return cmd
}
func buildPluginShowCommand(p *porter.Porter) *cobra.Command {
opts := porter.ShowPluginOptions{}
cmd := &cobra.Command{
Use: "show",
Short: "Show details about an installed plugin",
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.Validate(args)
},
RunE: func(cmd *cobra.Command, args []string) error {
return p.ShowPlugin(opts)
},
}
cmd.Flags().StringVarP(&opts.RawFormat, "output", "o", "table",
"Output format, allowed values are: table, json, yaml")
return cmd
}
func BuildPluginInstallCommand(p *porter.Porter) *cobra.Command {
opts := plugins.InstallOptions{}
cmd := &cobra.Command{
Use: "install NAME",
Short: "Install a plugin",
Long: `Install a plugin.
By default plugins are downloaded from the official Porter plugin feed at https://cdn.porter.sh/plugins/atom.xml. To download from a mirror, set the environment variable PORTER_MIRROR, or mirror in the Porter config file, with the value to replace https://cdn.porter.sh with.`,
Example: ` porter plugin install azure
porter plugin install azure --url https://cdn.porter.sh/plugins/azure
porter plugin install azure --feed-url https://cdn.porter.sh/plugins/atom.xml
porter plugin install azure --version v0.8.2-beta.1
porter plugin install azure --version canary`,
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.Validate(args)
},
RunE: func(cmd *cobra.Command, args []string) error {
return p.InstallPlugin(opts)
},
}
flags := cmd.Flags()
flags.StringVarP(&opts.Version, "version", "v", "latest",
"The plugin version. This can either be a version number, or a tagged release like 'latest' or 'canary'")
flags.StringVar(&opts.URL, "url", "",
"URL from where the plugin can be downloaded, for example https://github.com/org/proj/releases/downloads")
flags.StringVar(&opts.FeedURL, "feed-url", "",
"URL of an atom feed where the plugin can be downloaded. Defaults to the official Porter plugin feed.")
flags.StringVar(&opts.Mirror, "mirror", pkgmgmt.DefaultPackageMirror,
"Mirror of official Porter assets")
return cmd
}
func BuildPluginUninstallCommand(p *porter.Porter) *cobra.Command {
opts := pkgmgmt.UninstallOptions{}
cmd := &cobra.Command{
Use: "uninstall NAME",
Short: "Uninstall a plugin",
Example: ` porter plugin uninstall azure`,
PreRunE: func(cmd *cobra.Command, args []string) error {
return opts.Validate(args)
},
RunE: func(cmd *cobra.Command, args []string) error {
return p.UninstallPlugin(opts)
},
}
return cmd
}
func buildPluginRunCommand(p *porter.Porter) *cobra.Command {
cmd := &cobra.Command{
Use: "run KEY",
Short: "Serve internal plugins",
Run: func(cmd *cobra.Command, args []string) {
p.RunInternalPlugins(args)
},
Hidden: true, // This should ALWAYS be hidden, it is not a user-facing command
}
return cmd
}