diff --git a/cli/commands.go b/cli/commands.go new file mode 100644 index 000000000..b605fcf11 --- /dev/null +++ b/cli/commands.go @@ -0,0 +1,113 @@ +package main + +import ( + "github.com/gonuts/flag" + "github.com/jbenet/commander" + u "github.com/jbenet/go-ipfs/util" + "strings" + "time" +) + +var CmdIpfs = &commander.Command{ + UsageLine: "ipfs [] []", + Short: "global versioned p2p merkledag file system", + Long: `ipfs - global versioned p2p merkledag file system + +Basic commands: + + add Add an object to ipfs. + cat Show ipfs object data. + ls List links from an object. + refs List link hashes from an object. + +Tool commands: + + config Manage configuration. + version Show ipfs version information. + commands List all available commands. + +Advanced Commands: + + mount Mount a ipfs a read-only mountpoint. + +Use "ipfs help " for more information about a command. +`, + Run: ipfsCmd, + Subcommands: []*commander.Command{ + // cmdIpfsVersion, + // cmdIpfsConfig, + cmdIpfsCommands, + }, + Flag: *flag.NewFlagSet("ipfs", flag.ExitOnError), +} + +func ipfsCmd(c *commander.Command, args []string) error { + u.POut(c.Long) + return nil +} + +var cmdIpfsCommands = &commander.Command{ + UsageLine: "commands", + Short: "List all available commands.", + Long: `ipfs commands - List all available commands. + + Lists all available commands (and sub-commands) and exits. + `, + Run: commandsCmd, + Subcommands: []*commander.Command{ + cmdIpfsCommandsHelp, + }, +} + +func commandsCmd(c *commander.Command, args []string) error { + var listCmds func(c *commander.Command) + listCmds = func(c *commander.Command) { + u.POut("%s\n", c.FullSpacedName()) + for _, sc := range c.Subcommands { + listCmds(sc) + } + } + + listCmds(c.Parent) + return nil +} + +var cmdIpfsCommandsHelp = &commander.Command{ + UsageLine: "help", + Short: "List all available commands' help pages.", + Long: `ipfs commands help - List all available commands's help pages. + + Shows the pages of all available commands (and sub-commands) and exits. + Outputs a markdown document. + `, + Run: commandsHelpCmd, +} + +func commandsHelpCmd(c *commander.Command, args []string) error { + u.POut(referenceHeaderMsg) + u.POut("Generated on %s.\n\n", time.Now().UTC().Format("2006-01-02")) + + var printCmds func(*commander.Command, int) + printCmds = func(c *commander.Command, level int) { + u.POut("%s ", strings.Repeat("#", level)) + u.POut("%s\n\n", c.FullSpacedName()) + u.POut("```\n") + u.POut("%s\n", c.Long) + u.POut("```\n\n") + + for _, sc := range c.Subcommands { + printCmds(sc, level+1) + } + } + + printCmds(c.Parent.Parent, 1) + return nil +} + +const referenceHeaderMsg = ` +# ipfs command reference + +This document lists every ipfs command (including subcommands), along with +its help page. It can be viewed by running 'ipfs commands help'. + +` diff --git a/cli/ipfs b/cli/ipfs new file mode 100755 index 000000000..85caadf71 Binary files /dev/null and b/cli/ipfs differ diff --git a/cli/ipfs.go b/cli/ipfs.go new file mode 100644 index 000000000..5e6d4c066 --- /dev/null +++ b/cli/ipfs.go @@ -0,0 +1,17 @@ +package main + +import ( + "fmt" + "os" +) + +func main() { + err := CmdIpfs.Dispatch(os.Args[1:]) + if err != nil { + if len(err.Error()) > 0 { + fmt.Fprintf(os.Stderr, "%v\n", err) + } + os.Exit(1) + } + return +}