Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins-cli
提交
ff4a4ea9
J
jenkins-cli
项目概览
LinuxSuRen
/
jenkins-cli
与 Fork 源项目一致
Fork自
Jenkins 中文社区 / jenkins-cli
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins-cli
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ff4a4ea9
编写于
6月 29, 2019
作者:
LinuxSuRen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow user to add and remove config item
上级
b4a137a2
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
105 addition
and
0 deletion
+105
-0
app/cmd/config.go
app/cmd/config.go
+44
-0
app/cmd/config_add.go
app/cmd/config_add.go
+34
-0
app/cmd/config_remove.go
app/cmd/config_remove.go
+27
-0
未找到文件。
app/cmd/config.go
浏览文件 @
ff4a4ea9
...
...
@@ -134,6 +134,50 @@ func findJenkinsByName(name string) (jenkinsServer *JenkinsServer) {
return
}
func
addJenkins
(
jenkinsServer
JenkinsServer
)
(
err
error
)
{
jenkinsName
:=
jenkinsServer
.
Name
if
jenkinsName
==
""
{
err
=
fmt
.
Errorf
(
"Name cannot be empty"
)
return
}
if
findJenkinsByName
(
jenkinsName
)
!=
nil
{
err
=
fmt
.
Errorf
(
"Jenkins %s is existed"
,
jenkinsName
)
return
}
config
.
JenkinsServers
=
append
(
config
.
JenkinsServers
,
jenkinsServer
)
err
=
saveConfig
()
return
}
func
removeJenkins
(
name
string
)
(
err
error
)
{
current
:=
getCurrentJenkins
()
if
name
==
current
.
Name
{
err
=
fmt
.
Errorf
(
"You cannot remove current Jenkins"
)
}
index
:=
-
1
config
:=
getConfig
()
for
i
,
jenkins
:=
range
config
.
JenkinsServers
{
if
name
==
jenkins
.
Name
{
index
=
i
break
}
}
if
index
==
-
1
{
err
=
fmt
.
Errorf
(
"Cannot found by name %s"
,
name
)
}
else
{
config
.
JenkinsServers
[
index
]
=
config
.
JenkinsServers
[
len
(
config
.
JenkinsServers
)
-
1
]
config
.
JenkinsServers
[
len
(
config
.
JenkinsServers
)
-
1
]
=
JenkinsServer
{}
config
.
JenkinsServers
=
config
.
JenkinsServers
[
:
len
(
config
.
JenkinsServers
)
-
1
]
err
=
saveConfig
()
}
return
}
func
loadDefaultConfig
()
{
userHome
:=
userHomeDir
()
if
err
:=
loadConfig
(
fmt
.
Sprintf
(
"%s/.jenkins-cli.yaml"
,
userHome
));
err
!=
nil
{
...
...
app/cmd/config_add.go
0 → 100644
浏览文件 @
ff4a4ea9
package
cmd
import
(
"log"
"github.com/spf13/cobra"
)
type
ConfigAddOptions
struct
{
JenkinsServer
}
var
configAddOptions
ConfigAddOptions
func
init
()
{
configCmd
.
AddCommand
(
configAddCmd
)
configAddCmd
.
PersistentFlags
()
.
StringVarP
(
&
configAddOptions
.
Name
,
"name"
,
"n"
,
""
,
"Name of the Jenkins"
)
configAddCmd
.
PersistentFlags
()
.
StringVarP
(
&
configAddOptions
.
URL
,
"url"
,
""
,
""
,
"URL of the Jenkins"
)
configAddCmd
.
PersistentFlags
()
.
StringVarP
(
&
configAddOptions
.
UserName
,
"username"
,
"u"
,
""
,
"UserName of the Jenkins"
)
configAddCmd
.
PersistentFlags
()
.
StringVarP
(
&
configAddOptions
.
Token
,
"token"
,
"t"
,
""
,
"Token of the Jenkins"
)
configAddCmd
.
PersistentFlags
()
.
StringVarP
(
&
configAddOptions
.
Proxy
,
"proxy"
,
"p"
,
""
,
"Proxy of the Jenkins"
)
configAddCmd
.
PersistentFlags
()
.
StringVarP
(
&
configAddOptions
.
ProxyAuth
,
"proxyAuth"
,
"a"
,
""
,
"ProxyAuth of the Jenkins"
)
}
var
configAddCmd
=
&
cobra
.
Command
{
Use
:
"add"
,
Short
:
"Add a Jenkins config"
,
Long
:
`Add a Jenkins config`
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
if
err
:=
addJenkins
(
configAddOptions
.
JenkinsServer
);
err
!=
nil
{
log
.
Fatal
(
err
)
}
},
}
app/cmd/config_remove.go
0 → 100644
浏览文件 @
ff4a4ea9
package
cmd
import
(
"log"
"github.com/spf13/cobra"
)
func
init
()
{
configCmd
.
AddCommand
(
configRemoveCmd
)
}
var
configRemoveCmd
=
&
cobra
.
Command
{
Use
:
"remove"
,
Short
:
"Remove a Jenkins config"
,
Long
:
`Remove a Jenkins config`
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
if
len
(
args
)
==
0
{
log
.
Fatal
(
"You need to give a name"
)
}
target
:=
args
[
0
]
if
err
:=
removeJenkins
(
target
);
err
!=
nil
{
log
.
Fatal
(
err
)
}
},
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录