@cryptotaxi247 / kubo / commits / 0d06f2e50

refmt

Juan Batiz-Benet committed Jul 5, 2014 at 12:45 UTC 0d06f2e502ffc9b52c6620e5795e41f253215f73
3 files changed +107 -105
cli/commands.go
+43 -82
@@ -1,107 +1,68 @@
1 package main
2
3 import (
4 - "github.com/gonuts/flag"
5 - "github.com/jbenet/commander"
6 - u "github.com/jbenet/go-ipfs/util"
7 - "strings"
8 - "time"
4 + "github.com/jbenet/commander"
5 + u "github.com/jbenet/go-ipfs/util"
6 + "strings"
7 + "time"
8 )
9
11 -var CmdIpfs = &commander.Command{
12 - UsageLine: "ipfs [<flags>] <command> [<args>]",
13 - Short: "global versioned p2p merkledag file system",
14 - Long: `ipfs - global versioned p2p merkledag file system
15 -
16 -Basic commands:
17 -
18 - add <path> Add an object to ipfs.
19 - cat <ref> Show ipfs object data.
20 - ls <ref> List links from an object.
21 - refs <ref> List link hashes from an object.
22 -
23 -Tool commands:
24 -
25 - config Manage configuration.
26 - version Show ipfs version information.
27 - commands List all available commands.
28 -
29 -Advanced Commands:
30 -
31 - mount Mount a ipfs a read-only mountpoint.
32 -
33 -Use "ipfs help <command>" for more information about a command.
34 -`,
35 - Run: ipfsCmd,
36 - Subcommands: []*commander.Command{
37 - cmdIpfsVersion,
38 - // cmdIpfsConfig,
39 - cmdIpfsCommands,
40 - },
41 - Flag: *flag.NewFlagSet("ipfs", flag.ExitOnError),
42 -}
43 -
44 -func ipfsCmd(c *commander.Command, args []string) error {
45 - u.POut(c.Long)
46 - return nil
47 -}
48 -
10 var cmdIpfsCommands = &commander.Command{
50 - UsageLine: "commands",
51 - Short: "List all available commands.",
52 - Long: `ipfs commands - List all available commands.
11 + UsageLine: "commands",
12 + Short: "List all available commands.",
13 + Long: `ipfs commands - List all available commands.
14
15 Lists all available commands (and sub-commands) and exits.
16 `,
56 - Run: commandsCmd,
57 - Subcommands: []*commander.Command{
58 - cmdIpfsCommandsHelp,
59 - },
17 + Run: commandsCmd,
18 + Subcommands: []*commander.Command{
19 + cmdIpfsCommandsHelp,
20 + },
21 }
22
23 func commandsCmd(c *commander.Command, args []string) error {
63 - var listCmds func(c *commander.Command)
64 - listCmds = func(c *commander.Command) {
65 - u.POut("%s\n", c.FullSpacedName())
66 - for _, sc := range c.Subcommands {
67 - listCmds(sc)
68 - }
69 - }
70 -
71 - listCmds(c.Parent)
72 - return nil
24 + var listCmds func(c *commander.Command)
25 + listCmds = func(c *commander.Command) {
26 + u.POut("%s\n", c.FullSpacedName())
27 + for _, sc := range c.Subcommands {
28 + listCmds(sc)
29 + }
30 + }
31 +
32 + listCmds(c.Parent)
33 + return nil
34 }
35
36 var cmdIpfsCommandsHelp = &commander.Command{
76 - UsageLine: "help",
77 - Short: "List all available commands' help pages.",
78 - Long: `ipfs commands help - List all available commands's help pages.
37 + UsageLine: "help",
38 + Short: "List all available commands' help pages.",
39 + Long: `ipfs commands help - List all available commands's help pages.
40
41 Shows the pages of all available commands (and sub-commands) and exits.
42 Outputs a markdown document.
43 `,
83 - Run: commandsHelpCmd,
44 + Run: commandsHelpCmd,
45 }
46
47 func commandsHelpCmd(c *commander.Command, args []string) error {
87 - u.POut(referenceHeaderMsg)
88 - u.POut("Generated on %s.\n\n", time.Now().UTC().Format("2006-01-02"))
89 -
90 - var printCmds func(*commander.Command, int)
91 - printCmds = func(c *commander.Command, level int) {
92 - u.POut("%s ", strings.Repeat("#", level))
93 - u.POut("%s\n\n", c.FullSpacedName())
94 - u.POut("```\n")
95 - u.POut("%s\n", c.Long)
96 - u.POut("```\n\n")
97 -
98 - for _, sc := range c.Subcommands {
99 - printCmds(sc, level+1)
100 - }
101 - }
102 -
103 - printCmds(c.Parent.Parent, 1)
104 - return nil
48 + u.POut(referenceHeaderMsg)
49 + u.POut("Generated on %s.\n\n", time.Now().UTC().Format("2006-01-02"))
50 +
51 + var printCmds func(*commander.Command, int)
52 + printCmds = func(c *commander.Command, level int) {
53 + u.POut("%s ", strings.Repeat("#", level))
54 + u.POut("%s\n\n", c.FullSpacedName())
55 + u.POut("```\n")
56 + u.POut("%s\n", c.Long)
57 + u.POut("```\n\n")
58 +
59 + for _, sc := range c.Subcommands {
60 + printCmds(sc, level+1)
61 + }
62 + }
63 +
64 + printCmds(c.Parent.Parent, 1)
65 + return nil
66 }
67
68 const referenceHeaderMsg = `
cli/ipfs.go
+51 -10
@@ -1,17 +1,58 @@
1 package main
2
3 import (
4 - "fmt"
5 - "os"
4 + "fmt"
5 + "github.com/gonuts/flag"
6 + "github.com/jbenet/commander"
7 + u "github.com/jbenet/go-ipfs/util"
8 + "os"
9 )
10
11 +var CmdIpfs = &commander.Command{
12 + UsageLine: "ipfs [<flags>] <command> [<args>]",
13 + Short: "global versioned p2p merkledag file system",
14 + Long: `ipfs - global versioned p2p merkledag file system
15 +
16 +Basic commands:
17 +
18 + add <path> Add an object to ipfs.
19 + cat <ref> Show ipfs object data.
20 + ls <ref> List links from an object.
21 + refs <ref> List link hashes from an object.
22 +
23 +Tool commands:
24 +
25 + config Manage configuration.
26 + version Show ipfs version information.
27 + commands List all available commands.
28 +
29 +Advanced Commands:
30 +
31 + mount Mount a ipfs a read-only mountpoint.
32 +
33 +Use "ipfs help <command>" for more information about a command.
34 +`,
35 + Run: ipfsCmd,
36 + Subcommands: []*commander.Command{
37 + cmdIpfsVersion,
38 + // cmdIpfsConfig,
39 + cmdIpfsCommands,
40 + },
41 + Flag: *flag.NewFlagSet("ipfs", flag.ExitOnError),
42 +}
43 +
44 +func ipfsCmd(c *commander.Command, args []string) error {
45 + u.POut(c.Long)
46 + return nil
47 +}
48 +
49 func main() {
9 - err := CmdIpfs.Dispatch(os.Args[1:])
10 - if err != nil {
11 - if len(err.Error()) > 0 {
12 - fmt.Fprintf(os.Stderr, "%v\n", err)
13 - }
14 - os.Exit(1)
15 - }
16 - return
50 + err := CmdIpfs.Dispatch(os.Args[1:])
51 + if err != nil {
52 + if len(err.Error()) > 0 {
53 + fmt.Fprintf(os.Stderr, "%v\n", err)
54 + }
55 + os.Exit(1)
56 + }
57 + return
58 }
cli/version.go
+13 -13
@@ -1,31 +1,31 @@
1 package main
2
3 import (
4 - "github.com/jbenet/commander"
5 - u "github.com/jbenet/go-ipfs/util"
4 + "github.com/jbenet/commander"
5 + u "github.com/jbenet/go-ipfs/util"
6 )
7
8 const Version = "0.1.0"
9
10 var cmdIpfsVersion = &commander.Command{
11 - UsageLine: "version",
12 - Short: "Show ipfs version information.",
13 - Long: `ipfs version - Show ipfs version information.
11 + UsageLine: "version",
12 + Short: "Show ipfs version information.",
13 + Long: `ipfs version - Show ipfs version information.
14
15 Returns the current version of ipfs and exits.
16 `,
17 - Run: versionCmd,
17 + Run: versionCmd,
18 }
19
20 func init() {
21 - cmdIpfsVersion.Flag.Bool("number", false, "show only the number")
21 + cmdIpfsVersion.Flag.Bool("number", false, "show only the number")
22 }
23
24 func versionCmd(c *commander.Command, _ []string) error {
25 - number := c.Flag.Lookup("number").Value.Get().(bool)
26 - if !number {
27 - u.POut("ipfs version ")
28 - }
29 - u.POut("%s\n", Version)
30 - return nil
25 + number := c.Flag.Lookup("number").Value.Get().(bool)
26 + if !number {
27 + u.POut("ipfs version ")
28 + }
29 + u.POut("%s\n", Version)
30 + return nil
31 }