| 
									
										
										
										
											2016-02-15 21:09:34 +08:00
										 |  |  | package commands | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"github.com/codegangsta/cli" | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/cmd/grafana-cli/log" | 
					
						
							| 
									
										
										
										
											2016-02-15 23:11:37 +08:00
										 |  |  | 	"os" | 
					
						
							| 
									
										
										
										
											2016-02-15 21:09:34 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func runCommand(command func(commandLine CommandLine) error) func(context *cli.Context) { | 
					
						
							|  |  |  | 	return func(context *cli.Context) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		cmd := &contextCommandLine{context} | 
					
						
							|  |  |  | 		if err := command(cmd); err != nil { | 
					
						
							| 
									
										
										
										
											2016-03-11 21:11:25 +08:00
										 |  |  | 			log.Error("\nError: ") | 
					
						
							| 
									
										
										
										
											2016-03-07 23:41:22 +08:00
										 |  |  | 			log.Errorf("%s\n\n", err) | 
					
						
							| 
									
										
										
										
											2016-02-15 21:09:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			cmd.ShowHelp() | 
					
						
							| 
									
										
										
										
											2016-02-15 23:11:37 +08:00
										 |  |  | 			os.Exit(1) | 
					
						
							| 
									
										
										
										
											2016-02-15 21:09:34 +08:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2016-02-16 15:49:27 +08:00
										 |  |  | 			log.Info("\nRestart grafana after installing plugins . <service grafana-server restart>\n\n") | 
					
						
							| 
									
										
										
										
											2016-02-15 21:09:34 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var Commands = []cli.Command{ | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		Name:   "install", | 
					
						
							| 
									
										
										
										
											2016-02-16 15:49:27 +08:00
										 |  |  | 		Usage:  "install <plugin name>", | 
					
						
							| 
									
										
										
										
											2016-02-15 21:09:34 +08:00
										 |  |  | 		Action: runCommand(installCommand), | 
					
						
							|  |  |  | 	}, { | 
					
						
							|  |  |  | 		Name:   "list-remote", | 
					
						
							|  |  |  | 		Usage:  "list remote available plugins", | 
					
						
							|  |  |  | 		Action: runCommand(listremoteCommand), | 
					
						
							|  |  |  | 	}, { | 
					
						
							|  |  |  | 		Name:   "upgrade", | 
					
						
							| 
									
										
										
										
											2016-02-16 15:49:27 +08:00
										 |  |  | 		Usage:  "upgrade <plugin name>", | 
					
						
							| 
									
										
										
										
											2016-02-15 21:09:34 +08:00
										 |  |  | 		Action: runCommand(upgradeCommand), | 
					
						
							|  |  |  | 	}, { | 
					
						
							|  |  |  | 		Name:   "upgrade-all", | 
					
						
							|  |  |  | 		Usage:  "upgrades all your installed plugins", | 
					
						
							|  |  |  | 		Action: runCommand(upgradeAllCommand), | 
					
						
							|  |  |  | 	}, { | 
					
						
							|  |  |  | 		Name:   "ls", | 
					
						
							|  |  |  | 		Usage:  "list all installed plugins", | 
					
						
							|  |  |  | 		Action: runCommand(lsCommand), | 
					
						
							|  |  |  | 	}, { | 
					
						
							|  |  |  | 		Name:   "remove", | 
					
						
							| 
									
										
										
										
											2016-02-16 15:49:27 +08:00
										 |  |  | 		Usage:  "remove <plugin name>", | 
					
						
							| 
									
										
										
										
											2016-02-15 21:09:34 +08:00
										 |  |  | 		Action: runCommand(removeCommand), | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | } |