@cryptotaxi247 / kubo / commits / 81c6298a6

cli tool beginning

Juan Batiz-Benet committed Jul 5, 2014 at 02:00 UTC 81c6298a6f97f3be177b4d0a5d455f1ab256a071
3 files changed +130
cli/commands.go new
+113
@@ -0,0 +1,113 @@
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"
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 +var cmdIpfsCommands = &commander.Command{
50 + UsageLine: "commands",
51 + Short: "List all available commands.",
52 + Long: `ipfs commands - List all available commands.
53 +
54 + Lists all available commands (and sub-commands) and exits.
55 + `,
56 + Run: commandsCmd,
57 + Subcommands: []*commander.Command{
58 + cmdIpfsCommandsHelp,
59 + },
60 +}
61 +
62 +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
73 +}
74 +
75 +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.
79 +
80 + Shows the pages of all available commands (and sub-commands) and exits.
81 + Outputs a markdown document.
82 + `,
83 + Run: commandsHelpCmd,
84 +}
85 +
86 +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
105 +}
106 +
107 +const referenceHeaderMsg = `
108 +# ipfs command reference
109 +
110 +This document lists every ipfs command (including subcommands), along with
111 +its help page. It can be viewed by running 'ipfs commands help'.
112 +
113 +`
cli/ipfs
Binary files /dev/null and b/cli/ipfs differ
cli/ipfs.go new
+17
@@ -0,0 +1,17 @@
1 +package main
2 +
3 +import (
4 + "fmt"
5 + "os"
6 +)
7 +
8 +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
17 +}