| 
									
										
										
										
											2019-05-27 16:47:21 +08:00
										 |  |  | package utils | 
					
						
							| 
									
										
										
										
											2016-02-15 21:09:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"github.com/codegangsta/cli" | 
					
						
							| 
									
										
										
										
											2019-07-29 16:44:58 +08:00
										 |  |  | 	"github.com/grafana/grafana/pkg/cmd/grafana-cli/models" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/cmd/grafana-cli/services" | 
					
						
							| 
									
										
										
										
											2016-02-15 21:09:34 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type CommandLine interface { | 
					
						
							| 
									
										
										
										
											2019-10-15 22:44:15 +08:00
										 |  |  | 	ShowHelp() error | 
					
						
							| 
									
										
										
										
											2016-02-15 21:09:34 +08:00
										 |  |  | 	ShowVersion() | 
					
						
							|  |  |  | 	Application() *cli.App | 
					
						
							|  |  |  | 	Args() cli.Args | 
					
						
							|  |  |  | 	Bool(name string) bool | 
					
						
							|  |  |  | 	Int(name string) int | 
					
						
							|  |  |  | 	String(name string) string | 
					
						
							|  |  |  | 	StringSlice(name string) []string | 
					
						
							|  |  |  | 	GlobalString(name string) string | 
					
						
							|  |  |  | 	FlagNames() (names []string) | 
					
						
							|  |  |  | 	Generic(name string) interface{} | 
					
						
							| 
									
										
										
										
											2016-06-25 02:14:58 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	PluginDirectory() string | 
					
						
							|  |  |  | 	RepoDirectory() string | 
					
						
							| 
									
										
										
										
											2017-09-16 02:34:08 +08:00
										 |  |  | 	PluginURL() string | 
					
						
							| 
									
										
										
										
											2019-07-29 16:44:58 +08:00
										 |  |  | 	ApiClient() ApiClient | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type ApiClient interface { | 
					
						
							|  |  |  | 	GetPlugin(pluginId, repoUrl string) (models.Plugin, error) | 
					
						
							|  |  |  | 	DownloadFile(pluginName, filePath, url string, checksum string) (content []byte, err error) | 
					
						
							|  |  |  | 	ListAllPlugins(repoUrl string) (models.PluginRepo, error) | 
					
						
							| 
									
										
										
										
											2016-02-15 21:09:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-27 16:47:21 +08:00
										 |  |  | type ContextCommandLine struct { | 
					
						
							| 
									
										
										
										
											2016-02-15 21:09:34 +08:00
										 |  |  | 	*cli.Context | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-15 22:44:15 +08:00
										 |  |  | func (c *ContextCommandLine) ShowHelp() error { | 
					
						
							|  |  |  | 	return cli.ShowCommandHelp(c.Context, c.Command.Name) | 
					
						
							| 
									
										
										
										
											2016-02-15 21:09:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-27 16:47:21 +08:00
										 |  |  | func (c *ContextCommandLine) ShowVersion() { | 
					
						
							| 
									
										
										
										
											2016-02-15 21:09:34 +08:00
										 |  |  | 	cli.ShowVersion(c.Context) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-27 16:47:21 +08:00
										 |  |  | func (c *ContextCommandLine) Application() *cli.App { | 
					
						
							| 
									
										
										
										
											2016-02-15 21:09:34 +08:00
										 |  |  | 	return c.App | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-06-25 02:14:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-25 03:20:21 +08:00
										 |  |  | func (c *ContextCommandLine) HomePath() string { return c.GlobalString("homepath") } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (c *ContextCommandLine) ConfigFile() string { return c.GlobalString("config") } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-27 16:47:21 +08:00
										 |  |  | func (c *ContextCommandLine) PluginDirectory() string { | 
					
						
							| 
									
										
										
										
											2016-06-25 02:14:58 +08:00
										 |  |  | 	return c.GlobalString("pluginsDir") | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-27 16:47:21 +08:00
										 |  |  | func (c *ContextCommandLine) RepoDirectory() string { | 
					
						
							| 
									
										
										
										
											2016-06-25 02:14:58 +08:00
										 |  |  | 	return c.GlobalString("repo") | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-09-16 02:34:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-27 16:47:21 +08:00
										 |  |  | func (c *ContextCommandLine) PluginURL() string { | 
					
						
							| 
									
										
										
										
											2017-09-16 02:34:08 +08:00
										 |  |  | 	return c.GlobalString("pluginUrl") | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-06-25 03:20:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | func (c *ContextCommandLine) OptionsString() string { | 
					
						
							|  |  |  | 	return c.GlobalString("configOverrides") | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-07-29 16:44:58 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | func (c *ContextCommandLine) ApiClient() ApiClient { | 
					
						
							|  |  |  | 	return &services.GrafanaComClient{} | 
					
						
							|  |  |  | } |