2019-05-27 10:47:21 +02:00
|
|
|
package utils
|
2016-02-15 14:09:34 +01:00
|
|
|
|
|
|
|
|
import (
|
2019-11-06 13:42:58 +01:00
|
|
|
"os"
|
|
|
|
|
|
2019-07-29 10:44:58 +02:00
|
|
|
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
|
2020-02-26 12:27:31 +01:00
|
|
|
"github.com/urfave/cli/v2"
|
2016-02-15 14:09:34 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type CommandLine interface {
|
2019-10-15 16:44:15 +02:00
|
|
|
ShowHelp() error
|
2016-02-15 14:09:34 +01:00
|
|
|
ShowVersion()
|
|
|
|
|
Application() *cli.App
|
|
|
|
|
Args() cli.Args
|
|
|
|
|
Bool(name string) bool
|
|
|
|
|
Int(name string) int
|
|
|
|
|
String(name string) string
|
|
|
|
|
StringSlice(name string) []string
|
|
|
|
|
FlagNames() (names []string)
|
|
|
|
|
Generic(name string) interface{}
|
2016-06-24 20:14:58 +02:00
|
|
|
|
|
|
|
|
PluginDirectory() string
|
2021-04-26 16:13:40 +02:00
|
|
|
PluginRepoURL() string
|
2017-09-15 20:34:08 +02:00
|
|
|
PluginURL() string
|
2019-07-29 10:44:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ApiClient interface {
|
|
|
|
|
GetPlugin(pluginId, repoUrl string) (models.Plugin, error)
|
2019-11-06 13:42:58 +01:00
|
|
|
DownloadFile(pluginName string, tmpFile *os.File, url string, checksum string) (err error)
|
2019-07-29 10:44:58 +02:00
|
|
|
ListAllPlugins(repoUrl string) (models.PluginRepo, error)
|
2016-02-15 14:09:34 +01:00
|
|
|
}
|
|
|
|
|
|
2019-05-27 10:47:21 +02:00
|
|
|
type ContextCommandLine struct {
|
2016-02-15 14:09:34 +01:00
|
|
|
*cli.Context
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-15 16:44:15 +02:00
|
|
|
func (c *ContextCommandLine) ShowHelp() error {
|
|
|
|
|
return cli.ShowCommandHelp(c.Context, c.Command.Name)
|
2016-02-15 14:09:34 +01:00
|
|
|
}
|
|
|
|
|
|
2019-05-27 10:47:21 +02:00
|
|
|
func (c *ContextCommandLine) ShowVersion() {
|
2016-02-15 14:09:34 +01:00
|
|
|
cli.ShowVersion(c.Context)
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-27 10:47:21 +02:00
|
|
|
func (c *ContextCommandLine) Application() *cli.App {
|
2016-02-15 14:09:34 +01:00
|
|
|
return c.App
|
|
|
|
|
}
|
2016-06-24 20:14:58 +02:00
|
|
|
|
2020-02-26 12:27:31 +01:00
|
|
|
func (c *ContextCommandLine) HomePath() string { return c.String("homepath") }
|
2019-06-24 20:20:21 +01:00
|
|
|
|
2020-02-26 12:27:31 +01:00
|
|
|
func (c *ContextCommandLine) ConfigFile() string { return c.String("config") }
|
2019-06-24 20:20:21 +01:00
|
|
|
|
2019-05-27 10:47:21 +02:00
|
|
|
func (c *ContextCommandLine) PluginDirectory() string {
|
2020-02-26 12:27:31 +01:00
|
|
|
return c.String("pluginsDir")
|
2016-06-24 20:14:58 +02:00
|
|
|
}
|
|
|
|
|
|
2021-04-26 16:13:40 +02:00
|
|
|
func (c *ContextCommandLine) PluginRepoURL() string {
|
2020-02-26 12:27:31 +01:00
|
|
|
return c.String("repo")
|
2016-06-24 20:14:58 +02:00
|
|
|
}
|
2017-09-15 20:34:08 +02:00
|
|
|
|
2019-05-27 10:47:21 +02:00
|
|
|
func (c *ContextCommandLine) PluginURL() string {
|
2020-02-26 12:27:31 +01:00
|
|
|
return c.String("pluginUrl")
|
2017-09-15 20:34:08 +02:00
|
|
|
}
|