@cryptotaxi247 / kubo / commits / 8edfee2a5

cmd/ipfs: Removed new commands (to be refactored later)

Matt Bell committed Oct 27, 2014 at 18:46 UTC 8edfee2a582b559d0aa73ca6f19a3ace0c084ea7
3 files changed -513
cmd/ipfs/bootstrap.go deleted
-236
@@ -1,236 +0,0 @@
1 -package main
2 -
3 -import (
4 - "errors"
5 - "strings"
6 -
7 - "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
8 - "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
9 - ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
10 - mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
11 -
12 - config "github.com/jbenet/go-ipfs/config"
13 - peer "github.com/jbenet/go-ipfs/peer"
14 - u "github.com/jbenet/go-ipfs/util"
15 -)
16 -
17 -var cmdIpfsBootstrap = &commander.Command{
18 - UsageLine: "bootstrap",
19 - Short: "Show a list of bootstrapped addresses.",
20 - Long: `ipfs bootstrap - show, or manipulate bootstrap node addresses
21 -
22 -Running 'ipfs bootstrap' with no arguments will run 'ipfs bootstrap list'.
23 -
24 -Commands:
25 -
26 - list Show the boostrap list.
27 - add <address> Add a node's address to the bootstrap list.
28 - remove <address> Remove an address from the bootstrap list.
29 -
30 -` + bootstrapSecurityWarning,
31 - Run: bootstrapListCmd,
32 - Subcommands: []*commander.Command{
33 - cmdIpfsBootstrapRemove,
34 - cmdIpfsBootstrapAdd,
35 - cmdIpfsBootstrapList,
36 - },
37 - Flag: *flag.NewFlagSet("ipfs-bootstrap", flag.ExitOnError),
38 -}
39 -
40 -var cmdIpfsBootstrapRemove = &commander.Command{
41 - UsageLine: "remove <address | peerid>",
42 - Short: "Remove addresses from the bootstrap list.",
43 - Long: `ipfs bootstrap remove - remove addresses from the bootstrap list
44 -` + bootstrapSecurityWarning,
45 - Run: bootstrapRemoveCmd,
46 - Flag: *flag.NewFlagSet("ipfs-bootstrap-remove", flag.ExitOnError),
47 -}
48 -
49 -var cmdIpfsBootstrapAdd = &commander.Command{
50 - UsageLine: "add <address | peerid>",
51 - Short: "Add addresses to the bootstrap list.",
52 - Long: `ipfs bootstrap add - add addresses to the bootstrap list
53 -` + bootstrapSecurityWarning,
54 - Run: bootstrapAddCmd,
55 - Flag: *flag.NewFlagSet("ipfs-bootstrap-add", flag.ExitOnError),
56 -}
57 -
58 -var cmdIpfsBootstrapList = &commander.Command{
59 - UsageLine: "list",
60 - Short: "Show addresses in the bootstrap list.",
61 - Run: bootstrapListCmd,
62 - Flag: *flag.NewFlagSet("ipfs-bootstrap-list", flag.ExitOnError),
63 -}
64 -
65 -func bootstrapRemoveCmd(c *commander.Command, inp []string) error {
66 -
67 - if len(inp) == 0 {
68 - return errors.New("remove: no address or peerid specified")
69 - }
70 -
71 - toRemove, err := bootstrapInputToPeers(inp)
72 - if err != nil {
73 - return err
74 - }
75 -
76 - cfg, err := getConfig(c)
77 - if err != nil {
78 - return err
79 - }
80 -
81 - keep := []*config.BootstrapPeer{}
82 - remove := []*config.BootstrapPeer{}
83 -
84 - // function to filer what to keep
85 - shouldKeep := func(bp *config.BootstrapPeer) bool {
86 - for _, skipBP := range toRemove {
87 -
88 - // IDs must match to skip.
89 - if bp.PeerID != skipBP.PeerID {
90 - continue
91 - }
92 -
93 - // if Addresses match, or skipBP has no addr (wildcard)
94 - if skipBP.Address == bp.Address || skipBP.Address == "" {
95 - return false
96 - }
97 - }
98 - return true
99 - }
100 -
101 - // filter all the existing peers
102 - for _, currBP := range cfg.Bootstrap {
103 - if shouldKeep(currBP) {
104 - keep = append(keep, currBP)
105 - } else {
106 - remove = append(remove, currBP)
107 - }
108 - }
109 -
110 - // if didn't remove anyone, bail.
111 - if len(keep) == len(cfg.Bootstrap) {
112 - return errors.New("remove: peer given did not match any in list")
113 - }
114 -
115 - // write new config
116 - cfg.Bootstrap = keep
117 - if err := writeConfig(c, cfg); err != nil {
118 - return err
119 - }
120 -
121 - for _, bp := range remove {
122 - u.POut("removed %s\n", bp)
123 - }
124 - return nil
125 -}
126 -
127 -func bootstrapAddCmd(c *commander.Command, inp []string) error {
128 -
129 - if len(inp) == 0 {
130 - return errors.New("add: no address specified")
131 - }
132 -
133 - toAdd, err := bootstrapInputToPeers(inp)
134 - if err != nil {
135 - return err
136 - }
137 -
138 - cfg, err := getConfig(c)
139 - if err != nil {
140 - return err
141 - }
142 -
143 - // function to check whether a peer is already in the list.
144 - combine := func(lists ...[]*config.BootstrapPeer) []*config.BootstrapPeer {
145 -
146 - set := map[string]struct{}{}
147 - final := []*config.BootstrapPeer{}
148 -
149 - for _, list := range lists {
150 - for _, peer := range list {
151 - // if already in the set, continue
152 - _, found := set[peer.String()]
153 - if found {
154 - continue
155 - }
156 -
157 - set[peer.String()] = struct{}{}
158 - final = append(final, peer)
159 - }
160 - }
161 - return final
162 - }
163 -
164 - // combine both lists, removing dups.
165 - cfg.Bootstrap = combine(cfg.Bootstrap, toAdd)
166 - if err := writeConfig(c, cfg); err != nil {
167 - return err
168 - }
169 -
170 - for _, bp := range toAdd {
171 - u.POut("added %s\n", bp)
172 - }
173 - return nil
174 -}
175 -
176 -func bootstrapListCmd(c *commander.Command, inp []string) error {
177 -
178 - cfg, err := getConfig(c)
179 - if err != nil {
180 - return err
181 - }
182 -
183 - for _, bp := range cfg.Bootstrap {
184 - u.POut("%s\n", bp)
185 - }
186 -
187 - return nil
188 -}
189 -
190 -func bootstrapInputToPeers(input []string) ([]*config.BootstrapPeer, error) {
191 - split := func(addr string) (string, string) {
192 - idx := strings.LastIndex(addr, "/")
193 - if idx == -1 {
194 - return "", addr
195 - }
196 - return addr[:idx], addr[idx+1:]
197 - }
198 -
199 - peers := []*config.BootstrapPeer{}
200 - for _, addr := range input {
201 - addrS, peeridS := split(addr)
202 -
203 - // make sure addrS parses as a multiaddr.
204 - if len(addrS) > 0 {
205 - maddr, err := ma.NewMultiaddr(addrS)
206 - if err != nil {
207 - return nil, err
208 - }
209 -
210 - addrS = maddr.String()
211 - }
212 -
213 - // make sure idS parses as a peer.ID
214 - peerid, err := mh.FromB58String(peeridS)
215 - if err != nil {
216 - return nil, err
217 - }
218 -
219 - // construct config entry
220 - peers = append(peers, &config.BootstrapPeer{
221 - Address: addrS,
222 - PeerID: peer.ID(peerid).Pretty(),
223 - })
224 - }
225 - return peers, nil
226 -}
227 -
228 -const bootstrapSecurityWarning = `
229 -SECURITY WARNING:
230 -
231 -The bootstrap command manipulates the "bootstrap list", which contains
232 -the addresses of bootstrap nodes. These are the *trusted peers* from
233 -which to learn about other peers in the network. Only edit this list
234 -if you understand the risks of adding or removing nodes from this list.
235 -
236 -`
cmd/ipfs/config.go deleted
-143
@@ -1,143 +0,0 @@
1 -package main
2 -
3 -import (
4 - "errors"
5 - "fmt"
6 - "io"
7 - "os"
8 - "os/exec"
9 -
10 - "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
11 - "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
12 - config "github.com/jbenet/go-ipfs/config"
13 - u "github.com/jbenet/go-ipfs/util"
14 -)
15 -
16 -var cmdIpfsConfig = &commander.Command{
17 - UsageLine: "config",
18 - Short: "Get/Set ipfs config values",
19 - Long: `ipfs config [<key>] [<value>] - Get/Set ipfs config values.
20 -
21 - ipfs config <key> - Get value of <key>
22 - ipfs config <key> <value> - Set value of <key> to <value>
23 - ipfs config --show - Show config file
24 - ipfs config --edit - Edit config file in $EDITOR
25 -
26 -Examples:
27 -
28 - Get the value of the 'datastore.path' key:
29 -
30 - ipfs config datastore.path
31 -
32 - Set the value of the 'datastore.path' key:
33 -
34 - ipfs config datastore.path ~/.go-ipfs/datastore
35 -
36 -`,
37 - Run: configCmd,
38 - Flag: *flag.NewFlagSet("ipfs-config", flag.ExitOnError),
39 -}
40 -
41 -func init() {
42 - cmdIpfsConfig.Flag.Bool("edit", false, "Edit config file in $EDITOR")
43 - cmdIpfsConfig.Flag.Bool("show", false, "Show config file")
44 -}
45 -
46 -func configCmd(c *commander.Command, inp []string) error {
47 -
48 - confdir, err := getConfigDir(c.Parent)
49 - if err != nil {
50 - return err
51 - }
52 -
53 - filename, err := config.Filename(confdir)
54 - if err != nil {
55 - return err
56 - }
57 -
58 - // if editing, open the editor
59 - if c.Flag.Lookup("edit").Value.Get().(bool) {
60 - return configEditor(filename)
61 - }
62 -
63 - // if showing, cat the file
64 - if c.Flag.Lookup("show").Value.Get().(bool) {
65 - return configCat(filename)
66 - }
67 -
68 - if len(inp) == 0 {
69 - // "ipfs config" run without parameters
70 - u.POut(c.Long)
71 - return nil
72 - }
73 -
74 - // Getter (1 param)
75 - if len(inp) == 1 {
76 - value, err := config.ReadConfigKey(filename, inp[0])
77 - if err != nil {
78 - return fmt.Errorf("Failed to get config value: %s", err)
79 - }
80 -
81 - strval, ok := value.(string)
82 - if ok {
83 - u.POut("%s\n", strval)
84 - return nil
85 - }
86 -
87 - if err := config.Encode(os.Stdout, value); err != nil {
88 - return fmt.Errorf("Failed to encode config value: %s", err)
89 - }
90 - u.POut("\n")
91 - return nil
92 - }
93 -
94 - // Setter (>1 params)
95 - err = config.WriteConfigKey(filename, inp[0], inp[1])
96 - if err != nil {
97 - return fmt.Errorf("Failed to set config value: %s", err)
98 - }
99 -
100 - return nil
101 -}
102 -
103 -func configCat(filename string) error {
104 -
105 - file, err := os.Open(filename)
106 - if err != nil {
107 - return err
108 - }
109 - defer file.Close()
110 -
111 - if _, err = io.Copy(os.Stdout, file); err != nil {
112 - return err
113 - }
114 - u.POut("\n")
115 - return nil
116 -}
117 -
118 -func configEditor(filename string) error {
119 -
120 - editor := os.Getenv("EDITOR")
121 - if editor == "" {
122 - return errors.New("ENV variable $EDITOR not set")
123 - }
124 -
125 - cmd := exec.Command("sh", "-c", editor+" "+filename)
126 - cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr
127 - return cmd.Run()
128 -}
129 -
130 -func writeConfig(c *commander.Command, cfg *config.Config) error {
131 -
132 - confdir, err := getConfigDir(c)
133 - if err != nil {
134 - return err
135 - }
136 -
137 - filename, err := config.Filename(confdir)
138 - if err != nil {
139 - return err
140 - }
141 -
142 - return config.WriteConfigFile(filename, cfg)
143 -}
cmd/ipfs/tour.go deleted
-134
@@ -1,134 +0,0 @@
1 -// +build linux darwin freebsd
2 -
3 -package main
4 -
5 -import (
6 - "fmt"
7 -
8 - config "github.com/jbenet/go-ipfs/config"
9 - tour "github.com/jbenet/go-ipfs/tour"
10 -
11 - commander "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
12 -)
13 -
14 -var cmdIpfsTour = &commander.Command{
15 - UsageLine: "tour [<number>]",
16 - Short: "Take the IPFS Tour.",
17 - Long: `ipfs tour - Take the IPFS Tour.
18 -
19 - ipfs tour [<number>] - Show tour topic. Default to current.
20 - ipfs tour next - Show the next tour topic.
21 - ipfs tour list - Show a list of topics.
22 - ipfs tour restart - Restart the tour.
23 -
24 -This is a tour that takes you through various IPFS concepts,
25 -features, and tools to make sure you get up to speed with
26 -IPFS very quickly. To start, run:
27 -
28 - ipfs tour
29 -`,
30 - Run: tourCmd,
31 - Subcommands: []*commander.Command{
32 - cmdIpfsTourNext,
33 - cmdIpfsTourList,
34 - cmdIpfsTourRestart,
35 - },
36 -}
37 -
38 -var cmdIpfsTourNext = &commander.Command{
39 - UsageLine: "next",
40 - Short: "Show the next IPFS Tour topic.",
41 - Run: tourNextCmd,
42 -}
43 -
44 -var cmdIpfsTourList = &commander.Command{
45 - UsageLine: "list",
46 - Short: "Show a list of IPFS Tour topics.",
47 - Run: tourListCmd,
48 -}
49 -
50 -var cmdIpfsTourRestart = &commander.Command{
51 - UsageLine: "restart",
52 - Short: "Restart the IPFS Tour.",
53 - Run: tourRestartCmd,
54 -}
55 -
56 -func tourCmd(c *commander.Command, inp []string) error {
57 - cfg, err := getConfig(c)
58 - if err != nil {
59 - return err
60 - }
61 -
62 - topic := tour.TopicID(cfg.Tour.Last)
63 - if len(inp) > 0 {
64 - topic = tour.TopicID(inp[0])
65 - }
66 - return tourShow(topic)
67 -}
68 -
69 -func tourNextCmd(c *commander.Command, _ []string) error {
70 - cfg, err := getConfig(c)
71 - if err != nil {
72 - return err
73 - }
74 -
75 - topic := tour.NextTopic(tour.TopicID(cfg.Tour.Last))
76 - if err := tourShow(topic); err != nil {
77 - return err
78 - }
79 -
80 - // if topic didn't change (last) done
81 - if string(topic) == cfg.Tour.Last {
82 - return nil
83 - }
84 -
85 - // topic changed, not last. write it out.
86 - cfg.Tour.Last = string(topic)
87 - return writeConfig(c, cfg)
88 -}
89 -
90 -func tourListCmd(c *commander.Command, _ []string) error {
91 - cfg, err := getConfig(c)
92 - if err != nil {
93 - return err
94 - }
95 - lastid := tour.TopicID(cfg.Tour.Last)
96 -
97 - for _, id := range tour.IDs {
98 - c := ' '
99 - switch {
100 - case id == lastid:
101 - c = '*'
102 - case id.LessThan(lastid):
103 - c = '✓'
104 - }
105 -
106 - t := tour.Topics[id]
107 - fmt.Printf("- %c %-5.5s %s\n", c, id, t.Title)
108 - }
109 - return nil
110 -}
111 -
112 -func tourRestartCmd(c *commander.Command, _ []string) error {
113 - cfg, err := getConfig(c)
114 - if err != nil {
115 - return err
116 - }
117 -
118 - cfg.Tour.Last = ""
119 - return writeConfig(c, cfg)
120 -}
121 -
122 -func tourShow(id tour.ID) error {
123 - t, found := tour.Topics[id]
124 - if !found {
125 - return fmt.Errorf("no topic with id: %s", id)
126 - }
127 -
128 - fmt.Printf("Tour %s - %s\n\n%s\n", t.ID, t.Title, t.Text)
129 - return nil
130 -}
131 -
132 -func lastTour(cfg *config.Config) string {
133 - return ""
134 -}