Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
4131d8b5
Commit
4131d8b5
authored
Feb 16, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(cli): add command for upgrading one plugin
parent
36f4f1d0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
18 deletions
+42
-18
pkg/cmd/grafana-cli/commands/commands.go
+4
-4
pkg/cmd/grafana-cli/commands/install_command.go
+3
-4
pkg/cmd/grafana-cli/commands/upgrade_command.go
+26
-2
pkg/cmd/grafana-cli/services/io_util.go
+0
-3
pkg/cmd/grafana-cli/services/services.go
+9
-5
No files found.
pkg/cmd/grafana-cli/commands/commands.go
View file @
4131d8b5
...
...
@@ -16,7 +16,7 @@ func runCommand(command func(commandLine CommandLine) error) func(context *cli.C
cmd
.
ShowHelp
()
os
.
Exit
(
1
)
}
else
{
log
.
Info
(
"
Restart grafana after installing plugins . <service grafana-server restart>
\n
"
)
log
.
Info
(
"
\n
Restart grafana after installing plugins . <service grafana-server restart>
\n
\n
"
)
}
}
}
...
...
@@ -24,7 +24,7 @@ func runCommand(command func(commandLine CommandLine) error) func(context *cli.C
var
Commands
=
[]
cli
.
Command
{
{
Name
:
"install"
,
Usage
:
"install
s a plugin
"
,
Usage
:
"install
<plugin name>
"
,
Action
:
runCommand
(
installCommand
),
},
{
Name
:
"list-remote"
,
...
...
@@ -32,7 +32,7 @@ var Commands = []cli.Command{
Action
:
runCommand
(
listremoteCommand
),
},
{
Name
:
"upgrade"
,
Usage
:
"upgrade
s one plugin
"
,
Usage
:
"upgrade
<plugin name>
"
,
Action
:
runCommand
(
upgradeCommand
),
},
{
Name
:
"upgrade-all"
,
...
...
@@ -44,7 +44,7 @@ var Commands = []cli.Command{
Action
:
runCommand
(
lsCommand
),
},
{
Name
:
"remove"
,
Usage
:
"remove
s installed plugin
"
,
Usage
:
"remove
<plugin name>
"
,
Action
:
runCommand
(
removeCommand
),
},
}
pkg/cmd/grafana-cli/commands/install_command.go
View file @
4131d8b5
...
...
@@ -71,15 +71,14 @@ func InstallPlugin(pluginName, pluginFolder, version string) error {
err
=
downloadFile
(
plugin
.
Id
,
pluginFolder
,
downloadURL
)
if
err
==
nil
{
log
.
Info
(
"Installed %s
successfully ✔
\n
"
,
plugin
.
Id
)
log
.
Info
f
(
"Installed %v
successfully ✔
\n
"
,
plugin
.
Id
)
}
res
:=
s
.
ReadPlugin
(
pluginFolder
,
pluginName
)
res
,
_
:=
s
.
ReadPlugin
(
pluginFolder
,
pluginName
)
for
_
,
v
:=
range
res
.
Dependency
.
Plugins
{
log
.
Infof
(
"Installing Dependency: %s
\n
"
,
v
.
Id
)
InstallPlugin
(
v
.
Id
,
pluginFolder
,
""
)
log
.
Infof
(
"Installed Dependency: %v ✔
\n
"
,
v
.
Id
)
}
return
err
...
...
pkg/cmd/grafana-cli/commands/upgrade_command.go
View file @
4131d8b5
package
commands
import
(
"error
s"
s
"github.com/grafana/grafana/pkg/cmd/grafana-cli/service
s"
)
func
upgradeCommand
(
c
CommandLine
)
error
{
return
errors
.
New
(
"Not yet Implemented"
)
pluginDir
:=
c
.
GlobalString
(
"path"
)
pluginName
:=
c
.
Args
()
.
First
()
localPlugin
,
err
:=
s
.
ReadPlugin
(
pluginDir
,
pluginName
)
if
err
!=
nil
{
return
err
}
remotePlugins
,
err2
:=
s
.
ListAllPlugins
()
if
err2
!=
nil
{
return
err2
}
for
_
,
v
:=
range
remotePlugins
.
Plugins
{
if
localPlugin
.
Id
==
v
.
Id
{
if
ShouldUpgrade
(
localPlugin
.
Info
.
Version
,
v
)
{
s
.
RemoveInstalledPlugin
(
pluginDir
,
pluginName
)
return
InstallPlugin
(
localPlugin
.
Id
,
pluginDir
,
""
)
}
}
}
return
nil
}
pkg/cmd/grafana-cli/services/io_util.go
View file @
4131d8b5
package
services
import
(
//m "github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
"io/ioutil"
"os"
)
//var IoUtils m.IoUtil = IoUtilImp{}
type
IoUtilImp
struct
{
}
...
...
pkg/cmd/grafana-cli/services/services.go
View file @
4131d8b5
...
...
@@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"github.com/franela/goreq"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/log"
m
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
"path"
)
...
...
@@ -22,7 +23,7 @@ func ListAllPlugins() (m.PluginRepo, error) {
return
resp
,
nil
}
func
ReadPlugin
(
pluginDir
,
pluginName
string
)
m
.
InstalledPlugin
{
func
ReadPlugin
(
pluginDir
,
pluginName
string
)
(
m
.
InstalledPlugin
,
error
)
{
pluginDataPath
:=
path
.
Join
(
pluginDir
,
pluginName
,
"plugin.json"
)
pluginData
,
_
:=
IoHelper
.
ReadFile
(
pluginDataPath
)
...
...
@@ -34,24 +35,27 @@ func ReadPlugin(pluginDir, pluginName string) m.InstalledPlugin {
}
if
res
.
Id
==
""
{
re
s
.
Id
=
res
.
Name
re
turn
m
.
InstalledPlugin
{},
errors
.
New
(
"could not read find plugin "
+
pluginName
)
}
return
res
return
res
,
nil
}
func
GetLocalPlugins
(
pluginDir
string
)
[]
m
.
InstalledPlugin
{
result
:=
make
([]
m
.
InstalledPlugin
,
0
)
files
,
_
:=
IoHelper
.
ReadDir
(
pluginDir
)
for
_
,
f
:=
range
files
{
res
:=
ReadPlugin
(
pluginDir
,
f
.
Name
())
result
=
append
(
result
,
res
)
res
,
err
:=
ReadPlugin
(
pluginDir
,
f
.
Name
())
if
err
==
nil
{
result
=
append
(
result
,
res
)
}
}
return
result
}
func
RemoveInstalledPlugin
(
pluginPath
,
id
string
)
error
{
log
.
Infof
(
"Removing plugin: %v
\n
"
,
id
)
return
IoHelper
.
RemoveAll
(
path
.
Join
(
pluginPath
,
id
))
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment