提交 fcabf222 作者: Brian Tiger Chow 提交者: Juan Batiz-Benet

feat(ipfs2/config) impl show and edit as options

verified that option text hints match ipfs1 - btc
上级 45526224
package commands package commands
import ( import (
"bytes"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
...@@ -34,6 +36,10 @@ var configCmd = &cmds.Command{ ...@@ -34,6 +36,10 @@ var configCmd = &cmds.Command{
cmds.StringArg("key", true, false, "The key of the config entry (e.g. \"Addresses.API\")"), cmds.StringArg("key", true, false, "The key of the config entry (e.g. \"Addresses.API\")"),
cmds.StringArg("value", false, false, "The value to set the config entry to"), cmds.StringArg("value", false, false, "The value to set the config entry to"),
}, },
Options: []cmds.Option{
cmds.StringOption("show", "s", "Show config file"),
cmds.StringOption("edit", "e", "Edit config file in $EDITOR"),
},
Run: func(req cmds.Request) (interface{}, error) { Run: func(req cmds.Request) (interface{}, error) {
args := req.Arguments() args := req.Arguments()
...@@ -142,13 +148,12 @@ func setConfig(filename string, key, value string) (*ConfigField, error) { ...@@ -142,13 +148,12 @@ func setConfig(filename string, key, value string) (*ConfigField, error) {
func showConfig(filename string) (io.Reader, error) { func showConfig(filename string) (io.Reader, error) {
// TODO maybe we should omit privkey so we don't accidentally leak it? // TODO maybe we should omit privkey so we don't accidentally leak it?
file, err := os.Open(filename) data, err := ioutil.ReadFile(filename)
if err != nil { if err != nil {
return nil, err return nil, err
} }
//defer file.Close()
return file, nil return bytes.NewReader(data), nil
} }
func editConfig(filename string) error { func editConfig(filename string) error {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论