@cryptotaxi247 / kubo / commits / fcabf2226

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

verified that option text hints match ipfs1 - btc

Brian Tiger Chow committed Nov 11, 2014 at 22:08 UTC fcabf2226625a30a8c99529b80ae7df965096e82
1 file changed +8 -3
core/commands2/config.go
+8 -3
@@ -1,10 +1,12 @@
1 package commands
2
3 import (
4 + "bytes"
5 "encoding/json"
6 "errors"
7 "fmt"
8 "io"
9 + "io/ioutil"
10 "os"
11 "os/exec"
12
@@ -34,6 +36,10 @@ var configCmd = &cmds.Command{
36 cmds.StringArg("key", true, false, "The key of the config entry (e.g. \"Addresses.API\")"),
37 cmds.StringArg("value", false, false, "The value to set the config entry to"),
38 },
39 + Options: []cmds.Option{
40 + cmds.StringOption("show", "s", "Show config file"),
41 + cmds.StringOption("edit", "e", "Edit config file in $EDITOR"),
42 + },
43 Run: func(req cmds.Request) (interface{}, error) {
44 args := req.Arguments()
45
@@ -142,13 +148,12 @@ func setConfig(filename string, key, value string) (*ConfigField, error) {
148 func showConfig(filename string) (io.Reader, error) {
149 // TODO maybe we should omit privkey so we don't accidentally leak it?
150
145 - file, err := os.Open(filename)
151 + data, err := ioutil.ReadFile(filename)
152 if err != nil {
153 return nil, err
154 }
149 - //defer file.Close()
155
151 - return file, nil
156 + return bytes.NewReader(data), nil
157 }
158
159 func editConfig(filename string) error {