未验证 提交 040fc14b 编写于 作者: Z Zhao Xiaojie 提交者: GitHub

Merge pull request #70 from LinuxSuRen/fea/edit-config

Add support to edit the config file
package cmd
import (
"fmt"
"log"
"io/ioutil"
"github.com/AlecAivazis/survey"
"github.com/spf13/cobra"
)
func init() {
configCmd.AddCommand(configEditCmd)
}
var configEditCmd = &cobra.Command{
Use: "edit",
Short: "Edit a Jenkins config",
Long: `Edit a Jenkins config`,
Run: func(cmd *cobra.Command, args []string) {
current := getCurrentJenkins()
configPath := configOptions.ConfigFileLocation
var data []byte
var err error
if data, err = ioutil.ReadFile(configPath); err != nil {
log.Fatal(err)
}
content := string(data)
prompt := &survey.Editor{
Message: fmt.Sprintf("Edit config item %s", current.Name),
FileName: "*.yaml",
Help: fmt.Sprintf("Config file path: %s", configPath),
Default: content,
HideDefault: true,
AppendDefault: true,
}
if err := survey.AskOne(prompt, &content); err == nil {
if err = ioutil.WriteFile(configPath, []byte(content), 0644); err != nil {
log.Fatal(err)
}
} else {
log.Fatal(err)
}
},
}
......@@ -58,6 +58,7 @@ var jobBuildCmd = &cobra.Command{
Message: "Edit your pipeline script",
FileName: "*.sh",
Default: content,
HideDefault: true,
AppendDefault: true,
}
......
......@@ -35,6 +35,7 @@ var jobEditCmd = &cobra.Command{
Message: "Edit your pipeline script",
FileName: "*.sh",
Default: content,
HideDefault: true,
AppendDefault: true,
}
......
......@@ -36,9 +36,10 @@ var userEditCmd = &cobra.Command{
description := status.Description
prompt := &survey.Editor{
Message: "Edit your pipeline script",
Message: "Edit user description",
FileName: "*.sh",
Default: description,
HideDefault: true,
AppendDefault: true,
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册