Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jenkinsci
sub-group
Jenkins Cli
提交
b767b354
J
Jenkins Cli
项目概览
jenkinsci
/
sub-group
/
Jenkins Cli
通知
0
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
Jenkins Cli
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b767b354
编写于
7月 16, 2019
作者:
LinuxSuRen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add search sub-cmd for plugin
上级
ff4359c8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
134 addition
and
13 deletion
+134
-13
app/cmd/plugin.go
app/cmd/plugin.go
+2
-2
app/cmd/plugin_search.go
app/cmd/plugin_search.go
+67
-0
client/pluginManger.go
client/pluginManger.go
+65
-11
未找到文件。
app/cmd/plugin.go
浏览文件 @
b767b354
...
...
@@ -151,7 +151,7 @@ var pluginCmd = &cobra.Command{
}
if
plugins
,
err
:=
jclient
.
GetPlugins
();
err
==
nil
{
filteredPlugins
:=
make
([]
client
.
Plugin
,
0
)
filteredPlugins
:=
make
([]
client
.
Installed
Plugin
,
0
)
for
_
,
plugin
:=
range
plugins
.
Plugins
{
if
filter
{
if
hasUpdate
&&
!
plugin
.
HasUpdate
{
...
...
@@ -206,7 +206,7 @@ var pluginCmd = &cobra.Command{
func
(
o
*
PluginOptions
)
Output
(
obj
interface
{})
(
data
[]
byte
,
err
error
)
{
if
data
,
err
=
o
.
OutputOption
.
Output
(
obj
);
err
!=
nil
{
pluginList
:=
obj
.
([]
client
.
Plugin
)
pluginList
:=
obj
.
([]
client
.
Installed
Plugin
)
table
:=
util
.
CreateTable
(
os
.
Stdout
)
table
.
AddRow
(
"number"
,
"name"
,
"version"
,
"update"
)
for
i
,
plugin
:=
range
pluginList
{
...
...
app/cmd/plugin_search.go
0 → 100644
浏览文件 @
b767b354
package
cmd
import
(
"fmt"
"log"
"strings"
"github.com/linuxsuren/jenkins-cli/client"
"github.com/spf13/cobra"
)
type
PluginSearchOption
struct
{
OutputOption
}
var
pluginSearchOption
PluginSearchOption
func
init
()
{
pluginCmd
.
AddCommand
(
pluginSearchCmd
)
pluginSearchCmd
.
PersistentFlags
()
.
StringVarP
(
&
queueOption
.
Format
,
"output"
,
"o"
,
"json"
,
"Format the output"
)
}
var
pluginSearchCmd
=
&
cobra
.
Command
{
Use
:
"search <keyword>"
,
Short
:
"Print the plugins of your Jenkins"
,
Long
:
`Print the plugins of your Jenkins`
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
if
len
(
args
)
==
0
{
cmd
.
Help
()
return
}
keyword
:=
args
[
0
]
jenkins
:=
getCurrentJenkins
()
jclient
:=
&
client
.
PluginManager
{}
jclient
.
URL
=
jenkins
.
URL
jclient
.
UserName
=
jenkins
.
UserName
jclient
.
Token
=
jenkins
.
Token
jclient
.
Proxy
=
jenkins
.
Proxy
jclient
.
ProxyAuth
=
jenkins
.
ProxyAuth
if
plugins
,
err
:=
jclient
.
GetAvailablePlugins
();
err
==
nil
{
result
:=
searchPlugins
(
plugins
,
keyword
)
var
data
[]
byte
if
data
,
err
=
Format
(
result
,
queueOption
.
Format
);
err
==
nil
{
fmt
.
Printf
(
"%s
\n
"
,
string
(
data
))
}
else
{
log
.
Fatal
(
err
)
}
}
else
{
log
.
Fatal
(
err
)
}
},
}
func
searchPlugins
(
plugins
*
client
.
AvailablePluginList
,
keyword
string
)
[]
client
.
AvailablePlugin
{
result
:=
make
([]
client
.
AvailablePlugin
,
0
)
for
_
,
plugin
:=
range
plugins
.
Data
{
if
strings
.
Contains
(
plugin
.
Name
,
keyword
)
{
result
=
append
(
result
,
plugin
)
}
}
return
result
}
client/pluginManger.go
浏览文件 @
b767b354
...
...
@@ -13,27 +13,48 @@ type PluginManager struct {
JenkinsCore
}
type
Plugin
struct
{
Active
bool
Enabled
bool
Bundled
bool
Downgradable
bool
Deleted
bool
}
// PluginList represent a list of plugins
type
PluginList
struct
{
Plugins
[]
Plugin
type
Installed
PluginList
struct
{
Plugins
[]
Installed
Plugin
}
// Plugin represent the plugin from Jenkins
type
Plugin
struct
{
Active
bool
type
AvailablePluginList
struct
{
Data
[]
AvailablePlugin
Status
string
}
type
AvailablePlugin
struct
{
Plugin
// for the available list
Name
string
Installed
bool
Website
string
Title
string
}
// InstalledPlugin represent the installed plugin from Jenkins
type
InstalledPlugin
struct
{
Plugin
Enable
bool
ShortName
string
LongName
string
Version
string
URL
string
HasUpdate
bool
Enable
bool
Downgradable
bool
Pinned
bool
RequiredCoreVesion
string
MinimumJavaVersion
string
SupportDynamicLoad
string
Deleted
bool
Bundled
bool
BackVersion
string
}
...
...
@@ -59,7 +80,40 @@ func (p *PluginManager) CheckUpdate(handle func(*http.Response)) {
}
}
func
(
p
*
PluginManager
)
GetPlugins
()
(
pluginList
*
PluginList
,
err
error
)
{
func
(
p
*
PluginManager
)
GetAvailablePlugins
()
(
pluginList
*
AvailablePluginList
,
err
error
)
{
api
:=
fmt
.
Sprintf
(
"%s/pluginManager/plugins"
,
p
.
URL
)
var
(
req
*
http
.
Request
response
*
http
.
Response
)
req
,
err
=
http
.
NewRequest
(
"GET"
,
api
,
nil
)
if
err
==
nil
{
p
.
AuthHandle
(
req
)
}
else
{
return
}
client
:=
p
.
GetClient
()
if
response
,
err
=
client
.
Do
(
req
);
err
==
nil
{
code
:=
response
.
StatusCode
var
data
[]
byte
data
,
err
=
ioutil
.
ReadAll
(
response
.
Body
)
if
code
==
200
{
if
err
==
nil
{
pluginList
=
&
AvailablePluginList
{}
err
=
json
.
Unmarshal
(
data
,
pluginList
)
}
}
else
{
log
.
Fatal
(
string
(
data
))
}
}
else
{
log
.
Fatal
(
err
)
}
return
}
func
(
p
*
PluginManager
)
GetPlugins
()
(
pluginList
*
InstalledPluginList
,
err
error
)
{
api
:=
fmt
.
Sprintf
(
"%s/pluginManager/api/json?pretty=true&depth=1"
,
p
.
URL
)
var
(
req
*
http
.
Request
...
...
@@ -80,7 +134,7 @@ func (p *PluginManager) GetPlugins() (pluginList *PluginList, err error) {
data
,
err
=
ioutil
.
ReadAll
(
response
.
Body
)
if
code
==
200
{
if
err
==
nil
{
pluginList
=
&
PluginList
{}
pluginList
=
&
Installed
PluginList
{}
err
=
json
.
Unmarshal
(
data
,
pluginList
)
}
}
else
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录