grafana/pkg/cmd/grafana-cli/commands/commands.go

60 lines
1.3 KiB
Go
Raw Normal View History

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 {
log.Error("\nError: ")
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 {
log.Info("\nRestart grafana after installing plugins . <service grafana-server restart>\n\n")
2016-02-15 21:09:34 +08:00
}
}
}
var pluginCommands = []cli.Command{
2016-02-15 21:09:34 +08:00
{
Name: "install",
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",
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",
Usage: "remove <plugin name>",
2016-02-15 21:09:34 +08:00
Action: runCommand(removeCommand),
},
}
var Commands = []cli.Command{
{
Name: "plugins",
Usage: "Manage plugins for grafana",
Subcommands: pluginCommands,
},
}